An ADHD-friendly regular task tracker
修订版 | 6141390c06bd585219f264ba9e954559a8b60e1f (tree) |
---|---|
时间 | 2024-03-09 15:11:54 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Figure out the datetime maths.
Fuck, calendrical reasoning is so complicated sometimes.
@@ -16,26 +16,28 @@ app = Flask("every-card") | ||
16 | 16 | def root(): return "Working on it..." |
17 | 17 | |
18 | 18 | SHOW_QUERY = """ |
19 | -select label, description, unixepoch() - updated_at, unixepoch() - updated_at + consequences_after_s from tasks | |
19 | +select label, description, updated_at, consequences_after_s from tasks | |
20 | 20 | where updated_at + available_every_s <= unixepoch() and wheel = ? |
21 | 21 | order by updated_at + consequences_after_s |
22 | 22 | """ |
23 | 23 | |
24 | -def roundUp(delta): | |
25 | - print("rounding up", delta) | |
26 | - # return timedelta(seconds=delta).days + 1 | |
27 | - return timedelta(seconds=delta) | |
28 | -def roundDown(delta): | |
29 | - print("rounding down", delta) | |
30 | - # return timedelta(seconds=delta).days - 1 | |
31 | - return timedelta(seconds=delta) | |
24 | +def roundUp(delta): return timedelta(seconds=delta).days + 1 | |
25 | +def roundDown(delta): return timedelta(seconds=delta).days - 1 | |
26 | + | |
27 | +def formatTask(row): | |
28 | + now = datetime.now() | |
29 | + updated_at = datetime.fromtimestamp(row[2]) | |
30 | + updated_delta = now - updated_at | |
31 | + consequences_after = timedelta(seconds=row[3]) | |
32 | + consequences_at = updated_at + consequences_after | |
33 | + consequences_delta = now - consequences_at | |
34 | + return "<li>{1} ({0}): Last done {2} ago, needs to be done within {3}</li>".format( | |
35 | + html.escape(row[0]), html.escape(row[1]), updated_delta, | |
36 | + consequences_delta) | |
32 | 37 | |
33 | 38 | @app.route("/show/<wheel>") |
34 | 39 | def show(wheel): |
35 | - l = "".join("<li>{1} ({0}): Last done {2} days ago, needs to be done within the next {3} days</li>".format( | |
36 | - html.escape(row[0]), html.escape(row[1]), | |
37 | - roundUp(row[2]), roundDown(row[3])) | |
38 | - for row in cursor().execute(SHOW_QUERY, (wheel,))) | |
40 | + l = "".join(formatTask(row) for row in cursor().execute(SHOW_QUERY, (wheel,))) | |
39 | 41 | return "<!DOCTYPE html><h1>Tasks for {0}</h1><ol>{1}</ol>".format(wheel, l) |
40 | 42 | |
41 | 43 | app.run(debug=True, host="0.0.0.0", port=1312) |