From 8966127ed907d74772499676151f3b117b59c684 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 14 Oct 2020 17:16:30 -0500 Subject: [PATCH] update --- goalctl | 13 +++++++++++++ localwaka | 22 +++++++++++++++------- tweeter | 1 + 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/goalctl b/goalctl index c20d7c8..dca3e24 100755 --- a/goalctl +++ b/goalctl @@ -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() diff --git a/localwaka b/localwaka index 36d4e35..b6ee5e3 100755 --- a/localwaka +++ b/localwaka @@ -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() diff --git a/tweeter b/tweeter index eac5514..8e46a9b 100755 --- a/tweeter +++ b/tweeter @@ -1,4 +1,5 @@ #!/bin/bash +# tweet after reaching daily goal # vim: set ft=bash :