-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.py
139 lines (121 loc) · 4.36 KB
/
task.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from time_str_manipulation import TimeStr, TimeDict
class Task:
# anatomy of a Task object :-
# remind_time = { time, date }
# title = ""
# details = {
# description: ""
# start_time: ""
# end_time: ""
# }`
def __init__(self, remind_time_str, title="no title"):
self.remind_time = TimeDict.convert_time_dict(
TimeStr.validate_time_str(remind_time_str)
)
self.title = title
self.details = {}
def print(self):
print(f"title: {self.title}")
print(f"remind_time: {self.remind_time}")
if self.details:
print(self.details)
def update_details_description(self, new_val):
if new_val == "":
try:
del self.details['description']
except KeyError:
return
else:
self.details['description'] = new_val
def update_details_start_time(self, new_val):
if new_val == "":
try:
del self.details['start_time']
except KeyError:
return
else:
self.details['start_time'] = new_val
def update_details_end_time(self, new_val):
if new_val == "":
try:
del self.details['end_time']
except KeyError:
return
else:
self.details['end_time'] = new_val
def update_details_timings(self, timeTuple):
st, et = timeTuple
self.update_details_start_time(st)
self.update_details_end_time(et)
def update_title(self, new_val):
self.title = new_val if new_val != "" else "no title"
def compare_remind_time(self, task_other):
# compares remind_time of two Task objects
# returns integer value :-
# positive if remind_time is further than the other object
# negative if remind_time is nearer than the other object
# 0 if equal
remind_time_this = self.remind_time
remind_time_that = task_other.remind_time
def compare_date():
date_this = list(
map(
lambda x: int(x),
remind_time_this['date'].split('-')
)
)
date_that = list(
map(
lambda x: int(x),
remind_time_that['date'].split('-')
)
)
y_diff, m_diff, d_diff = [date_this[i] - date_that[i] for i in range(3)]
if y_diff != 0:
return y_diff
if m_diff != 0:
return m_diff
return d_diff
def compare_time():
time_this = list(
map(
lambda x: int(x),
remind_time_this['time'].split(':')
)
)
time_that = list(
map(
lambda x: int(x),
remind_time_that['time'].split(':')
)
)
h_diff, m_diff = [time_this[i] - time_that[i] for i in range(2)]
return h_diff if h_diff != 0 else m_diff
date_diff = compare_date()
return date_diff if date_diff != 0 else compare_time()
def export_details_str(self):
details_str = ""
if 'description' in self.details:
details_str += self.details['description'] + "\n"
if 'start_time' in self.details or 'end_time' in self.details:
details_str += "Event timings :-"
if 'start_time' in self.details:
details_str += "\nstart: " + self.details['start_time']
if 'end_time' in self.details:
details_str += "\nend: " + self.details['end_time']
details_str += "\n"
return details_str
def export_task_str(self, details_needed):
task_str = f"Remind time: {self.remind_time['time']}, {self.remind_time['date']}\n"
task_str += f"Title: {self.title}\n"
if details_needed:
details_str = self.export_details_str()
if details_str != "":
task_str += "\n" + details_str
return task_str
if __name__ == "__main__":
t1 = Task("1h 2m")
t1.update_details_description("Description of a Task object, for testing.")
t1.update_details_time(("5:00pm", "9:00pm"))
t1.update_title("Test Task")
print(t1.export_task_str(True))