-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_logic.py
More file actions
258 lines (220 loc) · 9.49 KB
/
search_logic.py
File metadata and controls
258 lines (220 loc) · 9.49 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#===================================Libraries====================================
from logic import Task
from ui import custom_time, clear, Search_loading, RED, YELLOW, GREEN, RESET
from datetime import datetime
#================================================================================
'''search in task list'''
def search_for_title(title_search):
clear()
found = 0
show_message = True
Search_loading()
try:
for i, search in enumerate(Task.to_do_list, start=1):
if search["Task title"] == title_search:
found += 1
if show_message and found:
print("")
print(f"The following tasks were found as title: '{title_search}':\n\n")
custom_time(.8)
print("====Task Search====\n\n")
show_message = False
print("Task number:", i)
for key, value in search.items():
print(YELLOW + f"{key:14}" + RESET + ":" + GREEN + f"{value}" + RESET)
print("-" * 30 + "\n")
except:
print("Something went wrong!")
custom_time(1.5)
return False
if not found:
return False
else:
return True
def search_for_time(time_search):
clear()
found = 0
show_message= True
real_time = datetime.now()
time_of_year = real_time.strftime("%Y-%m-%d")
earlier_time = None
modern_time = None
coming_time = None
stop_print1 = False
stop_print2 = False
stop_print3 = False
Search_loading()
try:
for i, search in enumerate(Task.to_do_list, start= 1):
if search["Task time"] == "time is deleted":
print(RED + "task time was deleted!")
custom_time(1)
print("Please adjust the task time." + RESET)
custom_time(1.2)
return False
if search["Task time"][11:] == time_search:
found += 1
#=================================================================
#Determine times
#=================================================================
#Past time
#If there were different times in the 'past', but they all held the same clock time
if search["Task time"][0:10] < time_of_year and stop_print1 and earlier_time:
if earlier_time == search["Task time"][0:10]:
stop_print1 = True
else:
earlier_time = search["Task time"][0:10]
stop_print1 = False
if search["Task time"][0:10] < time_of_year and not earlier_time:
earlier_time = search["Task time"][0:10]
#=================================================================
#Present time
if search["Task time"][0:10] == time_of_year:
modern_time = search["Task time"][0:10]
#=================================================================
#Future time
#If there are different times in the 'future', but they all hold the same clock time
if search["Task time"][0:10] > time_of_year and stop_print3 and coming_time:
if coming_time == search["Task time"][0:10]:
stop_print3 = True
else:
coming_time = search["Task time"][0:10]
stop_print3 = False
if search["Task time"][0:10] > time_of_year and not coming_time:
coming_time = search["Task time"][0:10]
#=================================================================
if show_message and found:
print("")
print(f"The following tasks were found as time: '{time_search}':\n\n")
custom_time(.8)
print("====Task Search====\n\n")
show_message = False
#Past
if earlier_time:
if not stop_print1:
print(f"\n====Task\s on {earlier_time}====\n")
stop_print1 = True
if search["Task time"][0:10] == earlier_time and search["Task time"][11:] == time_search:
print("Task number:", i)
for key, value in search.items():
print(YELLOW + f"{key:14}" + RESET + ":" + GREEN + f"{value}" + RESET)
print("-" * 30 + "\n")
# - - -
#Present
if modern_time:
if not stop_print2:
print(f"\n====Task\s on today====\n")
stop_print2 = True
if search["Task time"][0:10] == modern_time and search["Task time"][11:] == time_search:
print("Task number:", i)
for key, value in search.items():
print(YELLOW + f"{key:14}" + RESET + ":" + GREEN + f"{value}" + RESET)
print("-" * 30 + "\n")
# - - -
#Future
if coming_time:
if not stop_print3:
print(f"\n====Coming Task\s====\n")
stop_print3 = True
if search["Task time"][0:10] == coming_time and search["Task time"][11:] == time_search:
print("Task number:", i)
for key, value in search.items():
print(YELLOW + f"{key:14}" + RESET + ":" + GREEN + f"{value}" + RESET)
print("-" * 30 + "\n")
# - - -
except:
print("Something went wrong!")
custom_time(1.5)
return False
if not found:
return False
else:
return True
def search_for_status(status_search):
clear()
found = 0
show_message = True
Search_loading()
try:
for i, search in enumerate(Task.to_do_list, start= 1):
if search["Task status"] == status_search:
found += 1
if show_message and found:
print("")
print(f"The following tasks were found as status: '{status_search}':\n\n")
custom_time(.8)
print("====Task Search====\n\n")
show_message = False
print("Task number:", i)
for key, value in search.items():
print(YELLOW + f"{key:14}" + RESET + ":" + GREEN + f"{value}" + RESET)
print("-" * 30 + "\n")
except:
print("Something went wrong!")
custom_time(1.5)
return False
if not found:
return False
else:
return True
def do_custom_search(title_search, time_search, status_search):
clear()
found = 0
tasks_found = []
one_task = f"We found a task that matches your search data.\n\n"
more_tasks = f"We found several tasks that match your search criteria.\n\n"
Search_loading()
try:
for i, search in enumerate(Task.to_do_list, start=1):
if search["Task title"] == title_search and \
search["Task time"][11:] == time_search and \
search["Task status"] == status_search:
found += 1
tasks_found.append({
"Task number": i,
"Task title": search["Task title"],
"Task time": search["Task time"],
"Task status": search["Task status"]
})
if not found:
return False
print("\n" + (one_task if found == 1 else more_tasks))
custom_time(.8)
print("====Task Search====\n\n")
for t in tasks_found:
for k, v in t.items():
print(YELLOW + f"{k:14}" + RESET + ":" + GREEN + f"{v}" + RESET)
print("-" * 30 + "\n")
return True
except:
print("Something went wrong!")
custom_time(1.5)
return False
'''Search by task number'''
def search_by_number(task_number):
clear()
show_message = True
tasks_numbers = len(Task.to_do_list)
task_number -= 1
Search_loading()
try:
if 0 <= task_number < tasks_numbers:
if show_message:
print("")
print(f"The following tasks were found as task number: '{task_number+1}':\n\n")
custom_time(.8)
print("====Task Search====\n\n")
show_message = False
result = Task.to_do_list[task_number]
print("Task number:", task_number+1)
for k, v in result.items():
print(YELLOW + f"{k:14}" + RESET + ":" + GREEN + f"{v}" + RESET)
print("-" * 30 + "\n")
return True
else:
return False
except:
print("Something went wrong!")
custom_time(1.5)
return False
#================================================================================