• 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

修订版5e95eea18e5d87dd915e9ad159590a7be8281765 (tree)
时间2024-03-10 06:12:32
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Fix up the calendrical maths.

更改概述

差异

--- a/every-card.py
+++ b/every-card.py
@@ -18,26 +18,62 @@ def root(): return "Working on it..."
1818 SHOW_QUERY = """
1919 select label, description, updated_at, consequences_after_s from tasks
2020 where updated_at + available_every_s <= unixepoch() and wheel = ?
21-order by updated_at + consequences_after_s
21+order by updated_at + consequences_after_s desc
22+"""
23+
24+SHOW_ALL_QUERY = """
25+select description, available_every_s, consequences_after_s from tasks
26+where wheel=?
27+order by updated_at asc
2228 """
2329
2430 def roundUp(delta): return timedelta(seconds=delta).days + 1
2531 def roundDown(delta): return timedelta(seconds=delta).days - 1
2632
2733 def formatTask(row):
34+ label = html.escape(row[0])
2835 now = datetime.now()
2936 updated_at = datetime.fromtimestamp(row[2])
3037 updated_delta = now - updated_at
3138 consequences_after = timedelta(seconds=row[3])
3239 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)
40+ if consequences_at <= now:
41+ warning = "needs to be done immediately or there will be consequences"
42+ else:
43+ consequences_delta = consequences_at - now
44+ warning = "needs to be done within %d days" % consequences_delta.days
45+ return "<li>{1} ({0}): Last done {2} days ago, {3}</li>".format(
46+ label, html.escape(row[1]), updated_delta.days + 1, warning)
47+
48+def formatEvery(row):
49+ description = html.escape(row[0])
50+ available_every = timedelta(seconds=row[1]).days
51+ consequences_after = timedelta(seconds=row[2]).days
52+ return "<li>{0}: every {1} days, no less than every {2} days</li>".format(
53+ description, available_every, consequences_after)
3754
3855 @app.route("/show/<wheel>")
3956 def show(wheel):
40- l = "".join(formatTask(row) for row in cursor().execute(SHOW_QUERY, (wheel,)))
41- return "<!DOCTYPE html><h1>Tasks for {0}</h1><ol>{1}</ol>".format(wheel, l)
57+ c = cursor()
58+ l = "".join(formatTask(row) for row in c.execute(SHOW_QUERY, (wheel,)))
59+ dets = "".join(formatEvery(row)
60+ for row in c.execute(SHOW_ALL_QUERY, (wheel,)))
61+ return "<!DOCTYPE html><h1>Tasks for {0}</h1><ol>{1}</ol><details><ul>{2}</ul></details>".format(wheel, l, dets)
62+
63+UPDATED_AT_QUERY = """
64+select 1 from tasks
65+where wheel=? and label=?
66+"""
67+
68+@app.route("/do/<wheel>/<label>", methods=("POST",))
69+def do(wheel, label):
70+ c = cursor()
71+ t = c.execute(UPDATED_AT_QUERY, (wheel, label)).fetchone()
72+ if not t: return "No such task!"
73+
74+ c.execute("update tasks set updated_at=? where wheel=? and label=?",
75+ (time.time(), wheel, label))
76+ c.commit()
77+ return "Task done! Nice!"
4278
4379 app.run(debug=True, host="0.0.0.0", port=1312)
--- a/every.py
+++ b/every.py
@@ -49,7 +49,7 @@ def show(wheel):
4949 for row in c.execute(SHOW_QUERY, (wheel,)):
5050 print("Task:", row[1], "(" + row[0] + ")")
5151
52-updated_at_query = """
52+UPDATED_AT_QUERY = """
5353 select updated_at from tasks
5454 where wheel=? and label=?
5555 """
@@ -59,7 +59,7 @@ where wheel=? and label=?
5959 @click.argument("labels", nargs=-1)
6060 def do(wheel, labels):
6161 for label in labels:
62- t = c.execute(updated_at_query, (wheel, label)).fetchone()
62+ t = c.execute(UPDATED_AT_QUERY, (wheel, label)).fetchone()
6363 if not t:
6464 print("No such task")
6565 continue
--- a/flake.nix
+++ b/flake.nix
@@ -25,6 +25,10 @@
2525 chmod +x $out/bin/*
2626 patchShebangs $out/bin/every{,-card}
2727 '';
28+ doCheck = true;
29+ checkPhase = ''
30+ ${pkgs.python311Packages.pyflakes}/bin/pyflakes $out/bin/*
31+ '';
2832 };
2933 in {
3034 packages.default = every;