From 0af0849f13b2b97b5cd3f4229cde2b714f5e69b2 Mon Sep 17 00:00:00 2001 From: Stranck Date: Sat, 13 Jan 2024 13:13:22 +0100 Subject: [PATCH] Created tool to monitor new orders --- logOrders.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 logOrders.py diff --git a/logOrders.py b/logOrders.py new file mode 100644 index 0000000..9d2b607 --- /dev/null +++ b/logOrders.py @@ -0,0 +1,78 @@ +from config import * +import requests +import datetime +import time + +ROOM_CAPACITY_MAP = { + 0: 0, + # SACRO CUORE + 83: 11, + 67: 50, + 68: 45, + 69: 84, + 70: 10, + + # OVERFLOW 1 + 75: 50 +} + +def ans(data, name): + for p in data['positions']: + for a in p['answers']: + if a.get('question_identifier', None) == name: + if a['answer'] in ['True', 'False']: + return bool(a['answer'] == 'True') + return a['answer'] + return None + +def getOrders(): + ret = [] + p = 0 + + while 1: + p += 1 + res = requests.get(f"{base_url_event}orders/?page={p}", headers=headers) + + if res.status_code == 404: break + + data = res.json() + for o in data['results']: + + roomType = 0 + + for pos in o['positions']: + if pos['item'] == ITEMS_ID_MAP['bed_in_room']: + roomType = pos['variation'] + + ret.append({"code": o['code'], "fname": ans(o, 'fursona_name'), "rType": roomType, "date": o['datetime']}) + return ret + +ordersCode = set() +ordersTime = set() +ordersFName = set() +while True: + #try: + newOrders = getOrders() + shouldSleep = True + for o in newOrders: + if o['code'] not in ordersCode and not o['date'] in ordersTime and not o['fname'] in ordersFName: + + remainingInRoomType = ROOM_CAPACITY_MAP[o['rType']] + remainingInRoomType -= 1 + ROOM_CAPACITY_MAP[o['rType']] = remainingInRoomType + + roomCapacitiesStr = ", ".join(str(x).rjust(2, "0") for x in ROOM_CAPACITY_MAP.values()) + #dateStr = datetime.datetime.now().isoformat() + + print(f"[{o['date']}] {len(ordersCode)} - [{o['code']}] New order! FursonaName: {o['fname'].ljust(24)} - Room capacities: {roomCapacitiesStr}") + + shouldSleep = False + time.sleep(0.05) + ordersCode.add(o['code']) + ordersTime.add(o['date']) + ordersFName.add(o['fname']) + #except: + # print("Exception occurred!") + # pass + if shouldSleep: + time.sleep(1)