home · contact · privacy
In energy tracker, use buttons for different values, and add backdating.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 29 Jul 2023 21:21:41 +0000 (23:21 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 29 Jul 2023 21:21:41 +0000 (23:21 +0200)
energy_tracker.py

index 204b582cd25a2b66c0dd4bc103ff508ebc530446..444da172c3683d12e69d35b40d23fd605bd8c18e 100644 (file)
@@ -15,10 +15,16 @@ def build_page(entries):
 <body>
 <form action="/" method="POST">
 energy level:
-<input name="energy" type="number" step="1" min="-2" max="2" value="0" />
+<input type="submit" name="energy ---" value="---" />
+<input type="submit" name="energy --" value="--" />
+<input type="submit" name="energy -" value="-" />
+<input type="submit" name="energy +" value="+" />
+<input type="submit" name="energy ++" value="++" />
+<input type="submit" name="energy +++" value="+++" />
 comment:
 <input name="comment" type="text" />
-<input type="submit" value="submit!" />
+minutes ago:
+<input name="backdate" type="number" value="0" min="0" step="5" />
 </form>""" + f"""
 <details>
 <summary>
@@ -73,7 +79,12 @@ class MyServer(BaseHTTPRequestHandler):
         length = int(self.headers['content-length'])
         postvars = parse_qs(self.rfile.read(length), keep_blank_values=1)
         db = Database()
-        db.entries[str(datetime.datetime.now())[:19]] = [int(postvars[b'energy'][0].decode()), postvars[b'comment'][0].decode()] 
+        for val in ('---', '--', '-', '+', '++', '+++'):
+            val_name = 'energy ' + val
+            if val_name.encode() in postvars.keys():
+                time = datetime.datetime.now() - datetime.timedelta(minutes=int(postvars[b'backdate'][0].decode()))
+                db.entries[str(time)[:19]] = [val, postvars[b'comment'][0].decode()]
+                break
         try:
             db.write()
             self.send_response(302)