• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
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

Revision2d918ccd5331987ddf3127194c07f0e7484249c9 (tree)
Time2024-03-10 10:53:39
AuthorCorbin <cds@corb...>
CommiterCorbin

Log Message

Wire up basic buttons for doing tasks.

Change Summary

Incremental Difference

--- a/every-card.py
+++ b/every-card.py
@@ -1,18 +1,20 @@
11 #!/usr/bin/env python3
22
33 from datetime import datetime, timedelta
4-import html
4+import os
55 import sqlite3
6+import time
67
7-from flask import Flask, render_template
8+from flask import Flask, flash, redirect, render_template, url_for
89
910 # XXX Flask multithreading -> need to reconnect per-thread
1011 # XXX I think there's an extension that solves this?
11-def cursor(): return sqlite3.connect("every.db").cursor()
12+def connect(): return sqlite3.connect("every.db")
1213
1314 TEMPLATE_PATH = "@template_path@"
1415
1516 app = Flask("every-card", template_folder=TEMPLATE_PATH)
17+app.secret_key = os.urandom(16)
1618
1719 @app.route("/")
1820 def root(): return "Working on it..."
@@ -42,7 +44,8 @@ def deltaDays(s): return timedelta(seconds=s).days
4244
4345 @app.route("/show/<wheel>")
4446 def show(wheel):
45- c = cursor()
47+ conn = connect()
48+ c = conn.cursor()
4649 l = [(row[0], row[1]) + prepDates(row[2], row[3])
4750 for row in c.execute(SHOW_QUERY, (wheel,))]
4851 dets = c.execute(SHOW_ALL_QUERY, (wheel,))
@@ -56,13 +59,16 @@ where wheel=? and label=?
5659
5760 @app.route("/do/<wheel>/<label>", methods=("POST",))
5861 def do(wheel, label):
59- c = cursor()
62+ conn = connect()
63+ c = conn.cursor()
6064 t = c.execute(UPDATED_AT_QUERY, (wheel, label)).fetchone()
61- if not t: return "No such task!"
62-
63- c.execute("update tasks set updated_at=? where wheel=? and label=?",
64- (time.time(), wheel, label))
65- c.commit()
66- return "Task done! Nice!"
65+ if t:
66+ c.execute("update tasks set updated_at=? where wheel=? and label=?",
67+ (time.time(), wheel, label))
68+ conn.commit()
69+ flash("Task done! Nice!")
70+ else:
71+ flash("No such task!")
72+ return redirect(url_for("show", wheel=wheel))
6773
6874 app.run(debug=True, host="0.0.0.0", port=1312)
--- a/flake.nix
+++ b/flake.nix
@@ -10,6 +10,7 @@
1010 flake-utils.lib.eachDefaultSystem (system:
1111 let
1212 pkgs = import nixpkgs { inherit system; };
13+ pyflakes = pkgs.python311Packages.pyflakes;
1314 py = pkgs.python311.withPackages (ps: [
1415 ps.click ps.flask
1516 ]);
@@ -34,14 +35,14 @@
3435 '';
3536 doCheck = true;
3637 checkPhase = ''
37- ${pkgs.python311Packages.pyflakes}/bin/pyflakes $out/bin/*
38+ ${pyflakes}/bin/pyflakes $out/bin/*
3839 '';
3940 };
4041 in {
4142 packages.default = every;
4243 devShells.default = pkgs.mkShell {
4344 packages = [
44- py
45+ py pyflakes
4546 pkgs.sqlite pkgs.rlwrap
4647 ];
4748 };
--- a/show.html
+++ b/show.html
@@ -1,25 +1,42 @@
1-<!DOCTYPE html>
1+<!doctype html>
22
3-<h1>Tasks for {{ wheel }}</h1>
4-
5-<ol>
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>
15- {% endfor %}
16-</ol>
17-
18-<details>
19- <ul>
20- {% for description, available_every, consequences_after in allTasks %}
21- <li>{{ description }}: every {{ available_every | deltadays }}–{{
22- consequences_after | deltadays }} days</li>
3+<head>
4+ <title>Tasks for {{ wheel }}</title>
5+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6+</head>
7+<body>
8+ <div class="flashes">
9+ {% for message in get_flashed_messages() %}
10+ <div class="flash">
11+ {{ message }}
12+ </div>
13+ {% endfor %}
14+ </div>
15+ <h1>Tasks for {{ wheel }}</h1>
16+ <ol>
17+ {% for label, description, updated_delta, consequences_delta in availableTasks %}
18+ <li>
19+ <div class="button">
20+ <form action="{{ url_for("do", wheel=wheel, label=label) }}" method="POST">
21+ <input type="submit" value="Done!" />
22+ </form>
23+ </div>
24+ {{ description }} ({{ label }}): Last done {{ updated_delta.days + 1
25+ }} days ago,
26+ {% if consequences_delta.total_seconds() is lt(0) %}
27+ needs to be done immediately or there will be consequences
28+ {% else %}
29+ needs to be done within {{ consequences_delta.days }} days
30+ {% endif %}
31+ </li>
2332 {% endfor %}
24- </ul>
25-</details>
33+ </ol>
34+ <details>
35+ <ul>
36+ {% for description, available_every, consequences_after in allTasks %}
37+ <li>{{ description }}: every {{ available_every | deltadays }}–{{
38+ consequences_after | deltadays }} days</li>
39+ {% endfor %}
40+ </ul>
41+ </details>
42+</body>