From: Christian Heller Date: Mon, 2 Oct 2023 19:11:52 +0000 (+0200) Subject: Various improvements to calories counter. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/ledger?a=commitdiff_plain;h=26462d618eea05e4f4f468d34a9ff875ad1ebb4a;p=misc Various improvements to calories counter. --- diff --git a/calories.py b/calories.py index 771b11a..0f65aeb 100644 --- a/calories.py +++ b/calories.py @@ -1,6 +1,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer import os import json +import datetime def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows): return """ @@ -17,17 +18,15 @@ td, th {
- -{eatable_rows} + +{consumption_rows} - + - - - - - + + +
titlecaloriessugar (g)standard weight (g)commentsdelete
eatableunit countunit weight (g)caloriessugar (g)
add:add from DB:
@@ -35,20 +34,38 @@ td, th { {day_rows}
- -{consumption_rows} + +{eatable_rows} - + - - - + + + + +
eatableunit countunit weight (g)caloriessugar (g)
titlecaloriessugar (g)standard weight (g)commentsdelete
add from DB:add:
-""" + + +""" class LockFileDetected(Exception): pass @@ -140,8 +157,9 @@ class Database: return {"cals": calories, "sugar": sugar_g } def eatables_selection(self, selection=None): - html = '' # if selection else '' % (k, selected, v.title) return html @@ -152,7 +170,9 @@ class Database: def add_consumption(self, consumption): self.consumptions += [consumption] - def add_day(self, date, day): + def add_day(self, date, day, archives_today=False): + if archives_today: + date = date + str(datetime.datetime.now())[10:] self.days[date] = day def set_today_date(self, today_date): @@ -179,7 +199,6 @@ class MyServer(BaseHTTPRequestHandler): def do_POST(self): from uuid import uuid4 from urllib.parse import parse_qs - import datetime length = int(self.headers['content-length']) postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1) db = Database(False) @@ -220,8 +239,8 @@ class MyServer(BaseHTTPRequestHandler): if 'archive_day' in postvars.keys(): new_cals = postvars["new_day_cals"][0] new_sugar = postvars["new_day_sugar"][0] - db.add_day(db.today_date, Day(float(new_cals), float(new_sugar))) - db.set_today_date(str(datetime.datetime.now()))#[:10]) + db.add_day(db.today_date, Day(float(new_cals), float(new_sugar)), archives_today=True) + db.set_today_date(str(datetime.datetime.now())[:10]) db.consumptions = [] try: db.write() @@ -255,7 +274,7 @@ class MyServer(BaseHTTPRequestHandler): r = db.calc_consumption(c) consumptions += ""\ ""\ - ""\ + ""\ ""\ "%.1f"\ "%.1f"\ @@ -281,7 +300,7 @@ class MyServer(BaseHTTPRequestHandler): hostName = "localhost" -serverPort = 8080 +serverPort = 8081 if __name__ == "__main__": webServer = HTTPServer((hostName, serverPort), MyServer) print("Server started http://%s:%s" % (hostName, serverPort)) diff --git a/income_progress_bars.py b/income_progress_bars.py index 5a4f5ad..af2afd4 100644 --- a/income_progress_bars.py +++ b/income_progress_bars.py @@ -3,7 +3,7 @@ import os import json hostName = "localhost" -serverPort = 8080 +serverPort = 8081 header = """