home
·
contact
·
privacy
projects
/
misc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Various minor code improvements.
[misc]
/
calories.py
diff --git
a/calories.py
b/calories.py
index 54fb64e2d94be3f98ce2a743823c2c3db241a60a..dc40d5ff9e58cfaabf14ca2c43c6841e42dbd0c4 100644
(file)
--- a/
calories.py
+++ b/
calories.py
@@
-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,13
+298,14
@@
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():
- day_rows += "<tr>"\
+ 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>"\
"<td><input name=\"day_sugar\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
"<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>"\
"<td><input name=\"day_sugar\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
- "</tr>" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g)
- day_rows
+
= "<tr>"\
+ "</tr>" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g)
+ day_rows
+ day_rows = "<tr>"\
"<th>today:</th><th></th><th></th><th>archive?</th>"\
"</tr>"\
"<tr>"\
"<th>today:</th><th></th><th></th><th>archive?</th>"\
"</tr>"\
"<tr>"\
@@
-309,16
+313,14
@@
class MyServer(BaseHTTPRequestHandler):
"<td><input name=\"new_day_cals\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
"<td><input name=\"new_day_sugar\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
"<td><input name=\"archive_day\" type=\"checkbox\" /></td>"\
"<td><input name=\"new_day_cals\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
"<td><input name=\"new_day_sugar\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
"<td><input name=\"archive_day\" type=\"checkbox\" /></td>"\
- "</tr>" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g)
+ "</tr>" % (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"))
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)
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: