This commit is contained in:
Michael Zhang 2020-10-14 17:16:30 -05:00 committed by Michael Zhang
parent 474494f963
commit 8966127ed9
Signed by: michael
GPG Key ID: BDA47A31A3C8EE6B
3 changed files with 29 additions and 7 deletions

13
goalctl
View File

@ -58,6 +58,19 @@ if goal_type == "overall":
coded_secs = utils.get_seconds_coded(conn, start_time, end_time, timeout)
print("minutes coded:", (coded_secs/60))
# get all the entries
c = conn.cursor()
curs = c.execute("""
select time from heartbeats where time > ? and time < ? order by time;
""", [start_stamp, end_stamp])
coded_secs = 0
for (first, second) in window(curs, 2):
diff = second[0] - first[0]
if diff < timeout:
coded_secs += diff
print("coded: {}:{:02d} min".format(int(coded_secs)//60, int(coded_secs)%60))
elif data["interval"] == "week":
# start of the week
today = date.today()

View File

@ -1,17 +1,23 @@
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import socketserver
import sqlite3
import json
import configparser
from http.server import BaseHTTPRequestHandler
from collections import namedtuple
PORT = 5800
conn = sqlite3.connect("data.db")
c = conn.cursor()
c.execute("""
def post_heartbeat_hook():
pass
c0 = conn.cursor()
# c.execute("""drop table if exists "heartbeats" """)
c0.execute("""
create table if not exists "heartbeats" (
id int primary key,
entity text,
@ -49,7 +55,6 @@ class Handler(BaseHTTPRequestHandler):
)(*d.values())
data = json.loads(body, object_hook=object_hook)
print(data)
c = conn.cursor()
for heartbeat in data:
@ -80,12 +85,15 @@ class Handler(BaseHTTPRequestHandler):
)
conn.commit()
# run hooks
post_heartbeat_hook()
class Server(socketserver.TCPServer):
class Server(HTTPServer):
allow_reuse_address = True
def __init__(self):
super().__init__(("", PORT), Handler)
super().__init__(("127.0.0.1", PORT), Handler)
if __name__ == "__main__":
@ -95,4 +103,4 @@ if __name__ == "__main__":
except KeyboardInterrupt:
print("shutting down")
server.shutdown()
conn.close()
conn.close()

View File

@ -1,4 +1,5 @@
#!/bin/bash
# tweet after reaching daily goal
# vim: set ft=bash :