-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (67 loc) · 3.42 KB
/
main.py
File metadata and controls
80 lines (67 loc) · 3.42 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
from task_service import TaskService
from pathlib import Path
from datetime import datetime
def main():
print('\n-------------------------------------------------------------------- TASK TRACKER CLI -----------------------------------------------------------------\n')
file = Path(input('Enter the path for the tasks-file: '))
file_path = file.name
# Check for non existent or files other than JSON
while not file.exists() or not file_path.endswith('.json'):
print('\n----> Only existing JSON files are supported in this application.')
file = Path(input('\nEnter the path for the tasks-file: '))
file_path = file.name
# Instance of Task Service
Tasks = TaskService(file)
while True:
print("""\n
1. Create a Task.
2. Update status of a Task.
3. List tasks, filter by status, start-time and end-time.
4. Exit the application.
\n""")
option = input('Select one of the options above: ')
# Validate the selected option
while not option.isdigit() or option not in ['1', '2', '3', '4']:
print('\nOption must be a number between 1 and 4 both inclusive.\n')
option = input('Select one of the options above: ')
option = int(option)
# -------------- CREATE TASK ---------------
if option == 1:
task_name = input("\nEnter task name: ")
try:
Tasks.create_task(task_name)
print('\n>-------------------- Task created successfully --------------------<\n')
except Exception as e:
print('\nError: ', e)
# ------------- UPDATE STATUS --------------
elif option == 2:
task_id = input('\nEnter the task_id: ')
new_status = input('\nEnter new status: \nPick from these options:\n1.running\n2.pending\n3.done\n4.failed\n\n ---- ')
while new_status not in ['running', 'pending', 'done', 'failed']:
print('\nStatus must be one of the given options.\n')
new_status = input('\nEnter new status: \nPick from these options:\n1.running\n2.pending\n3.done\n4.failed\n\n ---- ')
try:
# update status and the tasks
Tasks.update_task_status(task_id, new_status)
print('\n>------------- Status Updated Successfully. ------------<')
except Exception as e:
print('\nError: ', e)
# -------------- LIST TASKS ----------------
elif option == 3:
start_time = input('\nEnter start time: ')
end_time = input('\nEnter end time: ')
status = input('\nEnter status: ')
try:
filtered_tasks = Tasks.list_tasks(start_time, end_time, status)
if len(filtered_tasks) > 0:
print('\n----------------------------------------------\n')
for task in filtered_tasks:
print(f"---> {task['name']}")
print('\n----------------------------------------------\n')
except Exception as e:
print('\nError: ', e)
else:
print('\n-------------------------------------------------------------------- TASK TRACKER CLI -----------------------------------------------------------------\n')
break
if __name__ == "__main__":
main()