• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

An ADHD-friendly regular task tracker


Commit MetaInfo

修订版6141390c06bd585219f264ba9e954559a8b60e1f (tree)
时间2024-03-09 15:11:54
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Figure out the datetime maths.

Fuck, calendrical reasoning is so complicated sometimes.

更改概述

差异

--- a/every-card.py
+++ b/every-card.py
@@ -16,26 +16,28 @@ app = Flask("every-card")
1616 def root(): return "Working on it..."
1717
1818 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
2020 where updated_at + available_every_s <= unixepoch() and wheel = ?
2121 order by updated_at + consequences_after_s
2222 """
2323
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)
3237
3338 @app.route("/show/<wheel>")
3439 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,)))
3941 return "<!DOCTYPE html><h1>Tasks for {0}</h1><ol>{1}</ol>".format(wheel, l)
4042
4143 app.run(debug=True, host="0.0.0.0", port=1312)