From: Christian Heller Date: Wed, 4 Oct 2023 18:20:28 +0000 (+0200) Subject: Various minor code improvements. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/edit?a=commitdiff_plain;h=a546cea97f153d5f6def4e46309dcb76038d7891;p=misc Various minor code improvements. --- diff --git a/calories.py b/calories.py index 7a4846a..dc40d5f 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 """ @@ -295,7 +298,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 +318,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: diff --git a/income_progress_bars.py b/income_progress_bars.py index af2afd4..1ecd8b9 100644 --- a/income_progress_bars.py +++ b/income_progress_bars.py @@ -257,7 +257,7 @@ class MyServer(BaseHTTPRequestHandler): 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: