added cheap status handler, printing to console
This commit is contained in:
parent
8dac698ca2
commit
b8d96c8b5a
23
DataStore.py
23
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
|
||||
|
19
dwtt
19
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user