From b0a87ecc527ed10db256909b97427a09e5379ea8 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 28 May 2024 22:59:09 -0700 Subject: [PATCH] Add more templates, use today_tomorrow_template function --- src/ptouch_web/dashapp.py | 70 +++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/ptouch_web/dashapp.py b/src/ptouch_web/dashapp.py index 4c908c4..0859a95 100644 --- a/src/ptouch_web/dashapp.py +++ b/src/ptouch_web/dashapp.py @@ -116,28 +116,57 @@ def print_button(print, label_text, font_size, copies): return res.text, 1 -def bottle_template(): +def today_tomorrow_template(template: str) -> str: today = datetime.now() tomorrow = today + timedelta(days=1) - return f"BM 4 floz\nexp {today.strftime('%b %d')}\nuse {tomorrow.strftime('%b %d')}" - - -def puree_template(): - tomorrow = datetime.now() + timedelta(days=1) - return f"\nPurée\nuse {tomorrow.strftime('%b %d')}" - - -def cracker_template(): - tomorrow = datetime.now() + timedelta(days=1) - return f"Graham\nCracker\nuse {tomorrow.strftime('%b %d')}" + return template.format( + today=today.strftime("%b %d"), tomorrow=tomorrow.strftime("%b %d") + ) templates = { - "bottle": {"label": "Bottle", "function": bottle_template}, - "rayleigh": {"label": "Rayleigh", "value": "Rayleigh\nArmstrong-Dodgen"}, - "kepler": {"label": "Kepler", "value": "Kepler\nArmstrong-Dodgen"}, - "puree": {"label": "Purée", "function": puree_template}, - "cracker": {"label": "Cracker", "function": cracker_template}, + "bottle": { + "label": "Bottle", + "function": today_tomorrow_template, + "template": "BM 5 floz\nexp {today}\nuse {tomorrow}", + }, + "rayleigh": {"label": "Rayleigh", "value": "Rayleigh\nArmstrong-\nDodgen"}, + "kepler": {"label": "Kepler", "value": "Kepler\nArmstrong-\nDodgen"}, + "puree": { + "label": "Purée", + "function": today_tomorrow_template, + "template": "\nPurée\nuse {tomorrow}", + }, + "cracker": { + "label": "Cracker", + "function": today_tomorrow_template, + "template": "Graham\nCracker\nuse {tomorrow}", + }, + "strawberries": { + "label": "Strawberries", + "function": today_tomorrow_template, + "template": "Sliced\nStrawberries\nuse {tomorrow}", + }, + "cheese": { + "label": "Cheese", + "function": today_tomorrow_template, + "template": "Cheese\nSticks\nuse {tomorrow}", + }, + "carrots": { + "label": "Carrots", + "function": today_tomorrow_template, + "template": "Cooked\nCarrots\nuse {tomorrow}", + }, + "sunbutter": { + "label": "Sunbutter", + "function": today_tomorrow_template, + "template": "Sunbutter\nJelly\nuse {tomorrow}", + }, + "pasta": { + "label": "Pasta", + "function": today_tomorrow_template, + "template": "Pasta\n\nuse {tomorrow}", + }, } for name, template in templates.items(): @@ -167,5 +196,10 @@ def template_button(button): if "value" in template: return template["value"] if "function" in template: - return template["function"]() + template_args = { + key: template[key] + for key in template + if key not in {"function", "name", "value", "label"} + } + return template["function"](**template_args) return "No template defined" -- 2.39.5