]> git.donarmstrong.com Git - ptouch_web.git/commitdiff
Add more templates, use today_tomorrow_template function
authorDon Armstrong <don@donarmstrong.com>
Wed, 29 May 2024 05:59:09 +0000 (22:59 -0700)
committerDon Armstrong <don@donarmstrong.com>
Wed, 29 May 2024 05:59:09 +0000 (22:59 -0700)
src/ptouch_web/dashapp.py

index 4c908c405f34f57f0c071534ff7788d623210bc9..0859a95843087bda15e2abdbca2f9b68471becd6 100644 (file)
@@ -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"