From 5af18b41784a7a68fc438c3c91cf801a87f7d498 Mon Sep 17 00:00:00 2001 From: matt venn Date: Thu, 16 Mar 2023 10:08:37 +0100 Subject: [PATCH] handle uni orders --- configure.py | 10 +++++----- orders.py | 31 ++++++++++++++++++++++++++++--- projects.yaml | 20 ++++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/configure.py b/configure.py index 266fb2a..5d37861 100755 --- a/configure.py +++ b/configure.py @@ -231,6 +231,11 @@ if __name__ == '__main__': ch.setFormatter(log_format) log.addHandler(ch) + if args.update_orders: + orders = Orders(config) + orders.fetch_orders() + orders.update_project_list() + projects = Projects(config, args) docs = Docs(projects.projects, args=args) @@ -242,11 +247,6 @@ if __name__ == '__main__': if args.metrics: projects.build_metrics() - if args.update_orders: - orders = Orders(config) - orders.fetch_orders() - orders.update_project_list() - if args.update_caravel: caravel.create_macro_config() caravel.instantiate() diff --git a/orders.py b/orders.py index 1b0c3b8..c5df24b 100644 --- a/orders.py +++ b/orders.py @@ -1,6 +1,9 @@ import stripe, os from datetime import datetime import yaml +import requests +import pytz +import logging class Orders(): @@ -12,8 +15,30 @@ class Orders(): self.orders = [] def fetch_orders(self): + orders = self.fetch_stripe_orders() + self.fetch_university_orders() + self.orders = sorted(orders, key=lambda d: d['time']) + + def fetch_university_orders(self): + name = self.config['name'] + url = f'https://app.tinytapeout.com/api/submissions?shuttle={name}' + r = requests.get(url) + if r.status_code != 200: + logging.warning("couldn't download {}".format(url)) + exit(1) + + orders = [] + for item in r.json()['items']: + orders.append({ + 'git_url' : item['repo'], + 'email' : None, + 'time' : datetime.strptime(item['time'], '%Y-%m-%dT%H:%M:%S.%f%z').replace(tzinfo=pytz.UTC) + }) + return orders + + def fetch_stripe_orders(self): start_id = None after_open_date = True + orders = [] while after_open_date: checkouts = stripe.checkout.Session.list(limit=10, starting_after=start_id) @@ -29,15 +54,15 @@ class Orders(): order = { 'git_url' : git_url, 'email' : checkout['customer_details']['email'], + 'time' : datetime.fromtimestamp(checkout['created']).replace(tzinfo=pytz.UTC), } - self.orders.append(order) + orders.append(order) # pagination start_id = checkout['id'] # put in date order - self.orders.reverse() - return self.orders + return orders def update_project_list(self): project_list = {} diff --git a/projects.yaml b/projects.yaml index 17b971c..b754ed1 100644 --- a/projects.yaml +++ b/projects.yaml @@ -3,15 +3,15 @@ status: active fill: false 1: - url: https://github.com/WallieEverest/tt03 + url: https://github.com/MichaelBell/tt03-hovalaag status: active fill: false 2: - url: https://github.com/icegoat9/tinytapeout03-7seglife + url: https://github.com/dgarrett/tt03-num-latch status: active fill: false 3: - url: https://github.com/meiniKi/tt03-another-piece-of-pi + url: https://github.com/KolosKoblasz/tt03-knight_rider status: active fill: false 4: @@ -19,25 +19,25 @@ status: active fill: false 5: - url: https://github.com/KolosKoblasz/tt03-knight_rider + url: https://github.com/meiniKi/tt03-another-piece-of-pi status: active fill: false 6: - url: https://github.com/dgarrett/tt03-num-latch + url: https://github.com/icegoat9/tinytapeout03-7seglife status: active fill: false 7: - url: https://github.com/MichaelBell/tt03-hovalaag + url: https://github.com/WallieEverest/tt03 status: active fill: false 8: - url: https://github.com/TinyTapeout/tt03-test-invert + url: https://github.com/yannickreiss/TT3_Memory status: active - fill: true + fill: false 9: - url: https://github.com/TinyTapeout/tt03-test-invert + url: https://github.com/yannickreiss/TT3_KS-Signal status: active - fill: true + fill: false 10: url: https://github.com/TinyTapeout/tt03-test-invert status: active