-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·67 lines (56 loc) · 2.19 KB
/
main.py
File metadata and controls
executable file
·67 lines (56 loc) · 2.19 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
import json
import sys
from pathlib import Path
from task import add_task, delete_task, update_task, list_tasks, mark_task, load_tasks, save_tasks
tasks_file = Path( "tasks.json" ).is_file()
if not tasks_file:
with open( "tasks.json", "w" ) as file:
json.dump( { "tasks":[] }, file, indent = 4 )
if len(sys.argv) > 1:
tasks_json = load_tasks( "tasks.json" )
tasks = tasks_json[ "tasks" ]
command = sys.argv[ 1 ]
id_commands = { "del", "mark-in-progress", "mark-done", "update" }
if command in id_commands and len( sys.argv ) > 2:
try:
task_id = int( sys.argv[ 2 ] )
except ValueError:
print( "The ID MUST be a number!" )
quit()
if command == "del":
if len( sys.argv ) > 2:
task_desc = sys.argv[ 2 ]
delete_task( task_id, tasks )
else:
print( "Please enter a task id to delete after the del command." )
if command == "add":
if len( sys.argv ) > 2:
task_desc = sys.argv[ 2 ]
add_task( task_desc, tasks )
else:
print( "Please enter a description enclosed in double quotation marks after the task id." )
if command == "update":
if len( sys.argv ) > 2:
task_desc = sys.argv[ 3 ]
update_task( task_id, tasks, task_desc )
else:
print( "Please enter a task id to update after the update command." )
if command == "list":
if len( sys.argv ) > 2:
sorting = sys.argv[ 2 ]
list_tasks( tasks_json, sorting )
else:
list_tasks( tasks_json )
if command == "mark-in-progress":
if len( sys.argv ) > 2:
mark_task( task_id, tasks, "in-progress" )
else:
print( "Please enter a task id to mark after the mark-in-progress command." )
if command == "mark-done":
if len( sys.argv ) > 2:
mark_task( task_id, tasks, "done" )
else:
print( "Please enter a task id to mark after the mark-done command." )
save_tasks( "tasks.json", tasks_json )
else:
print( "Please enter an argument when using the program." )