furizon_webint/export.py

53 lines
1.3 KiB
Python
Raw Normal View History

2023-01-17 21:24:20 +00:00
from sanic.response import text
from sanic import Blueprint, exceptions
from ext import *
from config import headers
bp = Blueprint("export", url_prefix="/manage/export")
@bp.route("/export.csv")
async def export_csv(request, order: Order):
if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!")
if order.code not in ['HWUC9','9YKGJ']: raise exceptions.Forbidden("Birichino :)")
2023-01-17 21:24:20 +00:00
page = 0
orders = {}
ret = 'status;code;nome;cognome;nick;nazione;tessera;artista;fursuiter;sponsorship;early;late;shirt;roomsize;roommembers;payment;price;refunds;staff\n'
2023-01-17 21:24:20 +00:00
while 1:
page += 1
r = httpx.get(f'https://reg.furizon.net/api/v1/organizers/furizon/events/beyond/orders/?page={page}', headers=headers)
if r.status_code == 404: break
for r in r.json()['results']:
o = Order(r)
orders[o.code] = o
ret += (';'.join(map(lambda x: str(x),
[
o.status,
2023-01-17 21:24:20 +00:00
o.code,
o.first_name,
o.last_name,
o.name,
o.country,
o.has_card or '',
o.is_artist or '',
o.is_fursuiter or '',
o.sponsorship or '',
o.has_early or '',
o.has_late or '',
o.shirt_size,
len(o.room_members),
','.join(o.room_members),
o.payment_provider,
o.total-o.fees,
o.refunds,
o.ans('staff_role') or 'attendee',
2023-01-17 21:24:20 +00:00
]))) + "\n"
return text(ret)