forked from artynusov/MacTimeLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tasks.py
56 lines (41 loc) · 1.63 KB
/
Tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#
# Tasks.py
# Class for working with tasks
#
# Copyright 2009 Artem Yunusov. All rights reserved.
#
from Timings import Timings
from DataManager import DataManager
TASK_TYPE = ("work", "slack", None)
class Tasks(object):
def __init__(self):
self.timings = Timings()
self.tasks = []
for date, task, projectName in DataManager.getAfterDate(Timings.workStartDateTime()):
self.processTask(date, task, projectName)
def processTask(self, date, task, projectName):
spentSeconds = self.timings.count(date, self.taskType(task))
attributes = (date, task, projectName, spentSeconds, self.taskType(task))
self.tasks.append(attributes)
return attributes
def dayStarted(self):
"""Return True if working day started else False"""
return bool(len(self.tasks))
def add(self, task, projectName=None):
date = Timings.now()
if self.taskType(task) != "work":
projectName = None
attributes = self.processTask(date, task, projectName)
DataManager.writeTask(date, task, projectName, firstToday=len(self.tasks) == 1)
return attributes
def setCurrentTask(self, task):
self.timings.setCurrentTaskType(self.taskType(task))
@property
def taskList(self):
return self.tasks
@staticmethod
def taskType(taskString):
return None if taskString.strip() == "" or taskString.find("***") != -1 \
else "work" if taskString.find("**") == -1 else "slack"
if __name__ == '__main__':
pass