X-Git-Url: https://plomlompom.com/repos/day_todos?a=blobdiff_plain;ds=sidebyside;f=calories.py;h=5ab57044eb3bd7333f7764ab62938d071473e72b;hb=d590f1c7a00fad8ac34336ca3751b66335b5055e;hp=54fb64e2d94be3f98ce2a743823c2c3db241a60a;hpb=8d8bb938a9d2248bd44ed53fdb0b87eff9ee2dd9;p=misc
diff --git a/calories.py b/calories.py
index 54fb64e..5ab5704 100644
--- a/calories.py
+++ b/calories.py
@@ -3,6 +3,9 @@ import os
import json
import datetime
+hostName = "localhost"
+serverPort = 8081
+
def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows):
return """
@@ -284,6 +287,7 @@ class MyServer(BaseHTTPRequestHandler):
"
| "\
"" % (k, v.title, v.cals, v.sugar_g, v.standard_g, v.comments, k)
consumptions = ""
+ db.consumptions = sorted(db.consumptions, key=lambda x: db.eatables[x.eatable_key].title)
for c in db.consumptions:
r = db.calc_consumption(c)
consumptions += "
"\
@@ -295,13 +299,14 @@ class MyServer(BaseHTTPRequestHandler):
"%.1f | "\
"" % (db.eatables_selection(c.eatable_key), c.unit_count, r["cals"], r["sugar"])
day_rows = ""
- for date, day in db.days.items():
- day_rows += ""\
+ for date in sorted(db.days.keys()):
+ day = db.days[date]
+ day_rows = "
"\
"%s | "\
"%.1f | "\
"%.1f | "\
- "
" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g)
- day_rows += ""\
+ "
" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g) + day_rows
+ day_rows = ""\
"today: | | | archive? | "\
"
"\
""\
@@ -309,16 +314,14 @@ class MyServer(BaseHTTPRequestHandler):
"%.1f | "\
"%.1f | "\
" | "\
- "
" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g)
+ "" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g) + day_rows
page = build_page(eatables, consumptions, db.eatables_selection(), day_rows)
self.wfile.write(bytes(page, "utf-8"))
-hostName = "localhost"
-serverPort = 8081
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
- print("Server started http://%s:%s" % (hostName, serverPort))
+ print(f"Server started http://{hostName}:{serverPort}")
try:
webServer.serve_forever()
except KeyboardInterrupt: