Fixed leaderboard, welcome, NFC scan, ...

This commit is contained in:
Ed 2023-05-26 00:58:44 +02:00
parent 86ceed6a93
commit 215921727f
2 changed files with 38 additions and 15 deletions

41
api.py
View File

@ -16,7 +16,7 @@ async def api_members(request):
ret = [] ret = []
for o in sorted(request.app.ctx.om.cache.values(), key=lambda x: len(x.room_members), reverse=True): for o in sorted(request.app.ctx.om.cache.values(), key=lambda x: len(x.room_members), reverse=True):
if o.status in ['c', 'e']: continue if o.status in ['expired', 'canceled']: continue
ret.append({ ret.append({
'code': o.code, 'code': o.code,
@ -40,16 +40,18 @@ async def api_leaderboard(request):
ret = [] ret = []
for o in sorted(request.app.ctx.om.cache.values(), key=lambda x: len(x.room_members), reverse=True): for o in request.app.ctx.om.cache.values():
if o.status in ['c', 'e']: continue if o.status in ['expired', 'canceled']: continue
ret.append({ ret.append({
'code': o.code, 'name': o.name,
'propic': o.ans('propic'), 'propic': o.ans('propic'),
'points': random.randint(0,50) if random.random() > 0.3 else '???' 'points': 0,
}) })
return response.json(sorted(ret, key=lambda x: x['points'], reverse=True)) ret = sorted(ret, key=lambda x: x['points'], reverse=True)
return response.json(ret)
@bp.route("/events.json") @bp.route("/events.json")
async def show_events(request): async def show_events(request):
@ -102,8 +104,14 @@ async def token_test(request):
@bp.get("/welcome") @bp.get("/welcome")
async def welcome_app(request): async def welcome_app(request):
ret = {
'phone': None,
'message': 'Reception open now!'
}
if not request.token: if not request.token:
return response.json({'ok': False, 'error': 'You need to provide a token.'}, status=401) return response.json(ret)
o = await request.app.ctx.om.get_order(code=request.token[:5]) o = await request.app.ctx.om.get_order(code=request.token[:5])
if not o or o.app_token != request.token[5:]: if not o or o.app_token != request.token[5:]:
@ -124,12 +132,9 @@ async def welcome_app(request):
'points': random.randint(0,50) if random.random() > 0.3 else 0, 'points': random.randint(0,50) if random.random() > 0.3 else 0,
'can_scan_nfc': o.can_scan_nfc, 'can_scan_nfc': o.can_scan_nfc,
'actual_room_id': o.actual_room_id, 'actual_room_id': o.actual_room_id,
'phone': '+3901234567890' **ret
}) })
@bp.get("/scan/<nfc_id>") @bp.get("/scan/<nfc_id>")
async def nfc_scan(request, nfc_id): async def nfc_scan(request, nfc_id):
if not request.token: if not request.token:
@ -142,8 +147,11 @@ async def nfc_scan(request, nfc_id):
if not user.can_scan_nfc: if not user.can_scan_nfc:
return response.json({'ok': False, 'error': 'You cannot scan NFC at this time.'}, status=401) return response.json({'ok': False, 'error': 'You cannot scan NFC at this time.'}, status=401)
for o in request.app.ctx.om.cache: for o in request.app.ctx.om.cache.values():
if o.nfc_id == nfc_id: if nfc_id in [o.nfc_id, o.code, o.barcode]:
room_owner = request.app.ctx.om.cache[o.room_id]
return response.json({ return response.json({
'code': o.code, 'code': o.code,
'sponsorship': o.sponsorship, 'sponsorship': o.sponsorship,
@ -158,10 +166,13 @@ async def nfc_scan(request, nfc_id):
'is_checked_in': False, 'is_checked_in': False,
'points': random.randint(0,50) if random.random() > 0.3 else 0, 'points': random.randint(0,50) if random.random() > 0.3 else 0,
'comment': o.comment, 'comment': o.comment,
'actual_room_id': o.actual_room_id 'actual_room_id': o.actual_room_id,
'phone': o.phone,
'telegram_username': o.telegram_username,
'roommates': [x for x in o.room_members if x != o.code]
}) })
return response.json({'ok': True, 'message': 'This NFC tag is not valid.'}) return response.json({'ok': False, 'error': 'This NFC tag is not valid.'})
@bp.get("/get_token/<code>/<login_code>") @bp.get("/get_token/<code>/<login_code>")
async def get_token_from_code(request, code, login_code): async def get_token_from_code(request, code, login_code):

12
ext.py
View File

@ -30,6 +30,7 @@ class Order:
self.first_name = None self.first_name = None
self.last_name = None self.last_name = None
self.country = None self.country = None
self.address = None
for p in self.data['positions']: for p in self.data['positions']:
if p['item'] in [16, 38]: if p['item'] in [16, 38]:
@ -37,6 +38,7 @@ class Order:
self.position_positionid = p['positionid'] self.position_positionid = p['positionid']
self.answers = p['answers'] self.answers = p['answers']
self.barcode = p['secret'] self.barcode = p['secret']
self.address = f"{p['street']} - {p['zipcode']} {p['city']} - {p['country']}"
if p['item'] == 17: if p['item'] == 17:
self.has_card = True self.has_card = True
@ -70,6 +72,7 @@ class Order:
self.payment_provider = data['payment_provider'] self.payment_provider = data['payment_provider']
self.comment = data['comment'] self.comment = data['comment']
self.phone = data['phone']
self.shirt_size = self.ans('shirt_size') self.shirt_size = self.ans('shirt_size')
self.is_artist = True if self.ans('is_artist') != 'No' else False self.is_artist = True if self.ans('is_artist') != 'No' else False
self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False
@ -80,6 +83,7 @@ class Order:
self.carpooling_message = json.loads(self.ans('carpooling_message')) if self.ans('carpooling_message') else {} self.carpooling_message = json.loads(self.ans('carpooling_message')) if self.ans('carpooling_message') else {}
self.karaoke_songs = json.loads(self.ans('karaoke_songs')) if self.ans('karaoke_songs') else {} self.karaoke_songs = json.loads(self.ans('karaoke_songs')) if self.ans('karaoke_songs') else {}
self.birth_date = self.ans('birth_date') self.birth_date = self.ans('birth_date')
self.birth_location = self.ans('birth_location')
self.name = self.ans('fursona_name') self.name = self.ans('fursona_name')
self.room_id = self.ans('room_id') self.room_id = self.ans('room_id')
self.room_confirmed = self.ans('room_confirmed') self.room_confirmed = self.ans('room_confirmed')
@ -93,6 +97,7 @@ class Order:
self.nfc_id = self.ans('nfc_id') self.nfc_id = self.ans('nfc_id')
self.can_scan_nfc = True if self.ans('can_scan_nfc') != 'No' else False self.can_scan_nfc = True if self.ans('can_scan_nfc') != 'No' else False
self.actual_room_id = self.ans('actual_room_id') self.actual_room_id = self.ans('actual_room_id')
self.telegram_username = self.ans('telegram_username').strip('@') if self.ans('telegram_username') else None
def __getitem__(self, var): def __getitem__(self, var):
return self.data[var] return self.data[var]
@ -140,6 +145,13 @@ class Order:
async def send_answers(self): async def send_answers(self):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
print("POSITION ID IS", self.position_id) print("POSITION ID IS", self.position_id)
for i, ans in enumerate(self.answers):
# Fix for karaoke fields
if ans['question'] == 40:
del self.answers[i]['options']
del self.answers[i]['option_identifiers']
res = await client.patch(join(base_url, f'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})
if res.status_code != 200: if res.status_code != 200: