Now using a config variable as api baseurl

This commit is contained in:
Ed 2022-12-18 17:48:29 +01:00
parent d8ea9e6bd1
commit 32f1260adc
4 changed files with 10 additions and 17 deletions

7
app.py
View File

@ -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!")

View File

@ -1 +1,2 @@
headers = {'Authorization': 'Token 2q5h7a2z9tqfz8ogu0qpriclwufelswc7obapw1mq2l1b4zaos7ebpz424zvz5gv'}
base_url = "https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/"

9
ext.py
View File

@ -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.")

10
room.py
View File

@ -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")