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) coded_secs = utils.get_seconds_coded(conn, start_time, end_time, timeout)
print("minutes coded:", (coded_secs/60)) 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": elif data["interval"] == "week":
# start of the week # start of the week
today = date.today() today = date.today()

View file

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

View file

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