X-Git-Url: https://plomlompom.com/repos//%22https:/validator.w3.org/check?a=blobdiff_plain;f=calories.py;h=5ab57044eb3bd7333f7764ab62938d071473e72b;hb=d590f1c7a00fad8ac34336ca3751b66335b5055e;hp=7a4846acdf40b5304fc5cc4ba088de48d16830da;hpb=35fe0ad6b60640e86add740c3b49dff05c75a240;p=misc diff --git a/calories.py b/calories.py index 7a4846a..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,7 +299,8 @@ 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(): + for date in sorted(db.days.keys()): + day = db.days[date] day_rows = ""\ "%s"\ "%.1f"\ @@ -314,11 +319,9 @@ class MyServer(BaseHTTPRequestHandler): 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: