• 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

修订版ae06d844044ab32a5fd40ee4cfb1aad533dacff2 (tree)
时间2024-03-10 10:08:47
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Put more string formatting into templates.

Also redo the calendrical maths again. This is one of the situations
where types would not help.

更改概述

差异

--- a/every-card.py
+++ b/every-card.py
@@ -20,7 +20,7 @@ def root(): return "Working on it..."
2020 SHOW_QUERY = """
2121 select label, description, updated_at, consequences_after_s from tasks
2222 where updated_at + available_every_s <= unixepoch() and wheel = ?
23-order by updated_at + consequences_after_s desc
23+order by updated_at + consequences_after_s asc
2424 """
2525
2626 SHOW_ALL_QUERY = """
@@ -32,33 +32,20 @@ order by updated_at asc
3232 def roundUp(delta): return timedelta(seconds=delta).days + 1
3333 def roundDown(delta): return timedelta(seconds=delta).days - 1
3434
35-def formatTask(row):
36- label = html.escape(row[0])
37- now = datetime.now()
38- updated_at = datetime.fromtimestamp(row[2])
39- updated_delta = now - updated_at
40- consequences_after = timedelta(seconds=row[3])
41- consequences_at = updated_at + consequences_after
42- if consequences_at <= now:
43- warning = "needs to be done immediately or there will be consequences"
44- else:
45- consequences_delta = consequences_at - now
46- warning = "needs to be done within %d days" % consequences_delta.days
47- return "{1} ({0}): Last done {2} days ago, {3}".format(
48- label, html.escape(row[1]), updated_delta.days + 1, warning)
49-
50-def formatEvery(row):
51- description = html.escape(row[0])
52- available_every = timedelta(seconds=row[1]).days
53- consequences_after = timedelta(seconds=row[2]).days
54- return "{0}: every {1} days, no less than every {2} days".format(
55- description, available_every, consequences_after)
35+def prepDates(updated_at_dt, consequences_after_s):
36+ updated_at = datetime.now() - datetime.fromtimestamp(updated_at_dt)
37+ consequences_after = timedelta(seconds=consequences_after_s)
38+ return updated_at, consequences_after - updated_at
39+
40+@app.template_filter("deltadays")
41+def deltaDays(s): return timedelta(seconds=s).days
5642
5743 @app.route("/show/<wheel>")
5844 def show(wheel):
5945 c = cursor()
60- l = [formatTask(row) for row in c.execute(SHOW_QUERY, (wheel,))]
61- dets = [formatEvery(row) for row in c.execute(SHOW_ALL_QUERY, (wheel,))]
46+ l = [(row[0], row[1]) + prepDates(row[2], row[3])
47+ for row in c.execute(SHOW_QUERY, (wheel,))]
48+ dets = c.execute(SHOW_ALL_QUERY, (wheel,))
6249 return render_template("show.html", wheel=wheel, availableTasks=l,
6350 allTasks=dets)
6451
--- a/show.html
+++ b/show.html
@@ -3,15 +3,23 @@
33 <h1>Tasks for {{ wheel }}</h1>
44
55 <ol>
6- {% for task in availableTasks %}
7- <li>{{ task }}</li>
6+ {% for label, description, updated_delta, consequences_delta in availableTasks %}
7+ <li>{{ description }} ({{ label }}): Last done {{ updated_delta.days + 1
8+ }} days ago,
9+ {% if consequences_delta.total_seconds() is lt(0) %}
10+ needs to be done immediately or there will be consequences
11+ {% else %}
12+ needs to be done within {{ consequences_delta.days }} days
13+ {% endif %}
14+ </li>
815 {% endfor %}
916 </ol>
1017
1118 <details>
1219 <ul>
13- {% for task in allTasks %}
14- <li>{{ task }}</li>
20+ {% for description, available_every, consequences_after in allTasks %}
21+ <li>{{ description }}: every {{ available_every | deltadays }}–{{
22+ consequences_after | deltadays }} days</li>
1523 {% endfor %}
1624 </ul>
1725 </details>