From: Christian Heller Date: Sat, 29 Jul 2023 21:21:41 +0000 (+0200) Subject: In energy tracker, use buttons for different values, and add backdating. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/cards/%7B%7B%20card_id%20%7D%7D/conditions?a=commitdiff_plain;h=636c08c1bbe04553c1a5ff3f2fe2b215d2551072;p=misc In energy tracker, use buttons for different values, and add backdating. --- diff --git a/energy_tracker.py b/energy_tracker.py index 204b582..444da17 100644 --- a/energy_tracker.py +++ b/energy_tracker.py @@ -15,10 +15,16 @@ def build_page(entries):
energy level: - + + + + + + comment: - +minutes ago: +
""" + f"""
@@ -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)