summaryrefslogtreecommitdiff
path: root/server.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2023-01-31 22:11:34 -0600
committerMark Powers <mark@marks.kitchen>2023-01-31 22:11:34 -0600
commitf74a597c0931122dff6f76452270633419472354 (patch)
tree82ed3de8c0e76e4c55f3797db0c39f16e69065df /server.py
parentad11ec7f93dca356748cb6c8bc49313a7ee7c3d7 (diff)
Add task timer
Diffstat (limited to 'server.py')
-rw-r--r--server.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/server.py b/server.py
index b678cf0..5a46c17 100644
--- a/server.py
+++ b/server.py
@@ -39,10 +39,13 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
u = urlparse(self.path)
print("GET", u.path)
+ print("/timer", u.path)
if u.path == "/":
self.send_static_file("index.html")
elif u.path == "/new_form":
self.send_static_file("new_form.html")
+ elif u.path == "/timer":
+ self.send_static_file("timer.html")
elif date_pattern.match(u.path[1:]):
with conn.cursor() as cur:
cur.execute("SELECT datatype, key, value FROM datapoint where date(created) = %s", (u.path[1:],))
@@ -65,6 +68,15 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(items).encode("utf-8"))
+ elif u.path == "/tasks":
+ with conn.cursor() as cur:
+ cur.execute("SELECT type FROM task")
+ items = []
+ for row in cur:
+ items.append(row[0])
+ self.send_response(200)
+ self.end_headers()
+ self.wfile.write(json.dumps(items).encode("utf-8"))
elif u.path == "/forms":
with conn.cursor() as cur:
cur.execute("SELECT type, prompt, prompt_id, extra FROM form ORDER BY id")
@@ -122,6 +134,15 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_response(204)
self.end_headers()
self.wfile.write(b"")
+ elif u.path == "/submit_task_time":
+ task_type = post_data.pop("type")
+ seconds = post_data.pop("seconds")
+ with conn.cursor() as cur:
+ cur.execute("INSERT INTO task_datapoint (type, seconds) VALUES (%s, %s)", (task_type, seconds))
+ conn.commit()
+ self.send_response(204)
+ self.end_headers()
+ self.wfile.write(b"")
else:
self.send_response(404)
self.end_headers()
@@ -133,6 +154,8 @@ def setup_db():
cur.execute("CREATE TABLE IF NOT EXISTS datapoint (id SERIAL PRIMARY KEY, created TIMESTAMP, datatype TEXT, key TEXT, value TEXT);")
cur.execute("CREATE TABLE IF NOT EXISTS outside_weather (id SERIAL PRIMARY KEY, created TIMESTAMP, temp FLOAT8, humidity FLOAT8, pressure FLOAT8, uvi FLOAT8, dew_point FLOAT8, wind_speed FLOAT8, wind_guest FLOAT8, wind_deg FLOAT8);")
cur.execute("CREATE TABLE IF NOT EXISTS book (id SERIAL PRIMARY KEY, title TEXT, completed BOOLEAN);")
+ cur.execute("CREATE TABLE IF NOT EXISTS task (id SERIAL PRIMARY KEY, type TEXT);")
+ cur.execute("CREATE TABLE IF NOT EXISTS task_datapoint (id SERIAL PRIMARY KEY, type TEXT, seconds TEXT);")
cur.execute("CREATE TABLE IF NOT EXISTS book_datapoint (id SERIAL PRIMARY KEY, created TIMESTAMP, book_id SERIAL, pages TEXT, CONSTRAINT fk_book FOREIGN KEY(book_id) REFERENCES book(id));")
cur.execute("CREATE TABLE IF NOT EXISTS email (id SERIAL PRIMARY KEY, created TIMESTAMP, username TEXT, domain TEXT);")
cur.execute("CREATE TABLE IF NOT EXISTS form (id SERIAL PRIMARY KEY, type TEXT, prompt TEXT, prompt_id TEXT, extra JSON);")