home · contact · privacy
Various minor code improvements.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 4 Oct 2023 18:20:28 +0000 (20:20 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 4 Oct 2023 18:20:28 +0000 (20:20 +0200)
calories.py
income_progress_bars.py

index 7a4846acdf40b5304fc5cc4ba088de48d16830da..dc40d5ff9e58cfaabf14ca2c43c6841e42dbd0c4 100644 (file)
@@ -3,6 +3,9 @@ import os
 import json
 import datetime
 
 import json
 import datetime
 
+hostName = "localhost"
+serverPort = 8081
+
 def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows):
     return """<html>
 <meta charset="UTF-8">
 def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows):
     return """<html>
 <meta charset="UTF-8">
@@ -295,7 +298,8 @@ class MyServer(BaseHTTPRequestHandler):
                     "<td>%.1f</td>"\
                     "</tr>" % (db.eatables_selection(c.eatable_key), c.unit_count, r["cals"], r["sugar"])
         day_rows = ""
                     "<td>%.1f</td>"\
                     "</tr>" % (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 = "<tr>"\
                     "<td><input name=\"day_date\" type=\"hidden\" value=\"%s\" />%s</td>"\
                     "<td><input name=\"day_cals\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
             day_rows = "<tr>"\
                     "<td><input name=\"day_date\" type=\"hidden\" value=\"%s\" />%s</td>"\
                     "<td><input name=\"day_cals\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
@@ -314,11 +318,9 @@ class MyServer(BaseHTTPRequestHandler):
         self.wfile.write(bytes(page, "utf-8"))
 
 
         self.wfile.write(bytes(page, "utf-8"))
 
 
-hostName = "localhost"
-serverPort = 8081
 if __name__ == "__main__":
     webServer = HTTPServer((hostName, serverPort), MyServer)
 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:
     try:
         webServer.serve_forever()
     except KeyboardInterrupt:
index af2afd484e87e9c911303b59a9c37b9866af3b2f..1ecd8b9a14452b0bc352084ef98ca7f4a8955140 100644 (file)
@@ -257,7 +257,7 @@ class MyServer(BaseHTTPRequestHandler):
 
 if __name__ == "__main__":        
     webServer = HTTPServer((hostName, serverPort), MyServer)
 
 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:
     try:
         webServer.serve_forever()
     except KeyboardInterrupt: