diff --git a/DataStore.py b/DataStore.py index 60c40cc..da30f6b 100644 --- a/DataStore.py +++ b/DataStore.py @@ -17,6 +17,12 @@ class TaskRef: self.taskid = taskid self.time = time +class Entry: + def __init__(self, date, seconds, taskid): + self.date = date + self.seconds = seconds + self.taskid = taskid + class DataStore: def __init__(self, dbfile): if not os.path.exists(dbfile): @@ -186,7 +192,7 @@ WHERE name = ? parenttask = self.getTaskByID(task.parentid) if parenttask is not None: parentpath = self.getTaskPath(parenttask) - path = parentpath + ' : ' + path + path = parentpath + ':' + path return path def createTask(self, name, longname, parentid): @@ -244,3 +250,18 @@ VALUES(?, ?, ?) ''', (date, taskid, seconds)) c.close() self.conn.commit() + + def getEntriesInDateRange(self, date1, date2): + entries = [] + c = self.conn.cursor() + c.execute(''' +SELECT date, seconds, taskid +FROM entries +WHERE date >= ? AND date <= ? +ORDER BY taskid, date +''', (date1.strftime('%Y-%m-%d'), date2.strftime('%Y-%m-%d'))) + for row in c: + entries.append(Entry(*row)) + c.close() + self.conn.commit() + return entries diff --git a/dwtt b/dwtt index 108bca3..ce63424 100755 --- a/dwtt +++ b/dwtt @@ -3,6 +3,7 @@ import os import sys import getopt +from datetime import datetime, timedelta from CmdWindow import CmdWindow from Command import Command @@ -105,10 +106,26 @@ def processTask(cmd, store): store.createTask(nameparts[-1].strip(), longname, None) return False +def processStatus(cmd, store): + now = datetime.now() + monday = now - timedelta(now.weekday()) + sunday = monday + timedelta(6) + entries = store.getEntriesInDateRange(monday, sunday) + prevtask = 0 + for ent in entries: + if ent.taskid != prevtask: + prevtask = ent.taskid + task = store.getTaskByID(ent.taskid) + print store.getTaskPath(task) + ':' + hours = round(float(ent.seconds) / (60 * 60), 1) + print ' %s: %0.1f' % (ent.date, hours) + return False + COMMAND_HANDLERS = { 'start' : processStart, 'out' : processOut, - 'task' : processTask + 'task' : processTask, + 'status' : processStatus } # Returns boolean for whether the command prompt should be displayed again