diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2025-03-15 21:31:49 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2025-03-15 21:31:49 +0000 |
| commit | ae23e62be8f232bf4f427d689ff8738c1255b30c (patch) | |
| tree | 5e871eb0d39be2f0c7ebe69959b3b4d4517daa88 | |
| parent | 932a17ad8375940ef5840bc3d6f0359ba0e9150e (diff) | |
Clean up some code & add example config
| -rw-r--r-- | config-example.yaml | 7 | ||||
| -rw-r--r-- | imggen.py | 3 | ||||
| -rw-r--r-- | main.py | 14 |
3 files changed, 15 insertions, 9 deletions
diff --git a/config-example.yaml b/config-example.yaml new file mode 100644 index 0000000..6367635 --- /dev/null +++ b/config-example.yaml @@ -0,0 +1,7 @@ +tito: + mac_token: + +printer: + maj: + min: + @@ -1,6 +1,5 @@ from PIL import Image, ImageDraw, ImageFont import math -import printer font_bold = ImageFont.truetype("/usr/share/fonts/TTF/IosevkaSS08-Bold.ttc", 70, encoding="unic") font_norm = ImageFont.truetype("/usr/share/fonts/TTF/IosevkaSS08-Regular.ttc", 40, encoding="unic") @@ -17,7 +16,7 @@ def name(name: str): draw = ImageDraw.Draw(img) draw.text((0, 0), name, font=font_bold, fill="black") - if font_bold.getlength(name) > MAX_WIDTH: + if txt_len > MAX_WIDTH: wpercent = (MAX_WIDTH / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((MAX_WIDTH, hsize), Image.Resampling.LANCZOS) @@ -56,14 +56,15 @@ async def create_checkin(request: Request): pizza_pref = list(filter(lambda a: a['question'] == 'What is your pizza preference?', content['answers'])) if len(pizza_pref) == 0: - return "ok" + return Response(status_code=204) + + d_reqs = None + q_d_reqs = list(filter(lambda a: a['question'] == 'Do you have any dietary restrictions?', content['answers'])) + if len(q_d_reqs) > 0: + d_reqs = q_d_reqs[0]['response'] - d_reqs = list(filter(lambda a: a['question'] == 'Do you have any dietary restrictions?', content['answers'])) logger.info(f"Printing food token for {attendee_name}...") - if len(d_reqs) == 0: - printer.print_food(attendee_name, pizza_pref[0]['response'], str(group), None) - else: - printer.print_food(attendee_name, pizza_pref[0]['response'], str(group), d_reqs[0]['response']) + printer.print_food(attendee_name, pizza_pref[0]['response'], str(group), d_reqs) serial = serial + 1 if serial % 10 == 0: @@ -73,7 +74,6 @@ async def create_checkin(request: Request): return Response(status_code=204) finally: lock.release() - if __name__ == '__main__': uvicorn.run(app, log_level="info", host="0.0.0.0", port=3000) |
