From 32f1260adca2063b48101777182eebd3f060da23 Mon Sep 17 00:00:00 2001 From: Ed Date: Sun, 18 Dec 2022 17:48:29 +0100 Subject: [PATCH] Now using a config variable as api baseurl --- app.py | 7 +++---- config.py | 1 + ext.py | 9 +++++---- room.py | 10 +--------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 606b609..d1ea9ae 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from time import time import httpx import re import json +from os.path import join from ext import * from config import * @@ -44,7 +45,7 @@ async def redirect_explore(request, code, secret, order: Order, secret2=None): if not order: async with httpx.AsyncClient() as client: - res = await client.get(f"https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orders/{code}/", headers=headers) + res = await client.get(join(base_url, f"orders/{code}/"), headers=headers) if res.status_code != 200: raise exceptions.NotFound("This order code does not exist. Check that your order wasn't deleted, or the link is correct.") @@ -63,8 +64,6 @@ async def welcome(request, order: Order, quota: Quotas): pending_roommates = [] if order.pending_roommates: - print('Oleee') - print(order.ans('pending_roommates')) for pr in order.pending_roommates: if not pr: continue print(pr) @@ -102,7 +101,7 @@ async def download_ticket(request, order: Order, quota: Quotas): raise exceptions.Forbidden("You are not allowed to download this ticket.") async with httpx.AsyncClient() as client: - res = await client.get(f"https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orders/{order.code}/download/pdf/", headers=headers) + res = await client.get(join(base_url, f"orders/{order.code}/download/pdf/"), headers=headers) if res.status_code != 200: raise exceptions.FileNotFound("Your ticket hasn't been generated yet. Please try later!") diff --git a/config.py b/config.py index 17fa113..e292f7e 100644 --- a/config.py +++ b/config.py @@ -1 +1,2 @@ headers = {'Authorization': 'Token 2q5h7a2z9tqfz8ogu0qpriclwufelswc7obapw1mq2l1b4zaos7ebpz424zvz5gv'} +base_url = "https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/" diff --git a/ext.py b/ext.py index 8cfc1ec..11a349b 100644 --- a/ext.py +++ b/ext.py @@ -3,6 +3,7 @@ from sanic import Request, exceptions import httpx import re from config import * +from os.path import join @dataclass class Order: @@ -56,7 +57,7 @@ class Order: if (not found) and (new_answer is not None): async with httpx.AsyncClient() as client: - res = await client.get('https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/questions/', headers=headers) + res = await client.get(join(base_url, 'questions/'), headers=headers) res = res.json() for r in res['results']: @@ -72,7 +73,7 @@ class Order: async def send_answers(self): async with httpx.AsyncClient() as client: - res = await client.patch(f'https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orderpositions/{self.position_id}/', headers=headers, json={'answers': self.answers}) + res = await client.patch(join(base_url, f'orderpositions/{self.position_id}/'), headers=headers, json={'answers': self.answers}) @dataclass class Quotas: @@ -93,7 +94,7 @@ class Quotas: async def get_quotas(request: Request=None): async with httpx.AsyncClient() as client: - res = await client.get(f"https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/quotas/?order=id&with_availability=true", headers=headers) + res = await client.get(join(base_url, 'quotas/?order=id&with_availability=true'), headers=headers) res = res.json() return Quotas(res) @@ -107,7 +108,7 @@ async def get_order(request: Request=None, code=None, secret=None, insecure=Fals if re.match('^[A-Z0-9]{5}$', code or '') and (secret is None or re.match('^[a-z0-9]{16,}$', secret)): print('Trying to get a session from stored', code, secret) async with httpx.AsyncClient() as client: - res = await client.get(f"https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orders/{code}/", headers=headers) + res = await client.get(join(base_url, f"orders/{code}/"), headers=headers) if res.status_code != 200: if request: raise exceptions.Forbidden("Your session has expired due to order deletion or change! Please check your E-Mail for more info.") diff --git a/room.py b/room.py index a1efb2e..3e99cc0 100644 --- a/room.py +++ b/room.py @@ -252,9 +252,6 @@ async def confirm_room(request, order: Order, quotas: Quotas): await rm.edit_answer('pending_roommates', None) await rm.edit_answer('pending_room', None) - print(room_members) - print(len(room_members)) - thing = { 'order': order.code, 'addon_to': order.position_positionid, @@ -263,12 +260,7 @@ async def confirm_room(request, order: Order, quotas: Quotas): } async with httpx.AsyncClient() as client: - res = await client.post("https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orderpositions/", headers=headers, json=thing) - - print(thing) - print(res.json()) - - print(res.status_code) + res = await client.post(join(base_url, "orderpositions/"), headers=headers, json=thing) if res.status_code != 201: raise exceptions.BadRequest("Something has gone wrong! Please contact support immediately")