<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>
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)