-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
71 lines (49 loc) · 1.88 KB
/
cli.py
File metadata and controls
71 lines (49 loc) · 1.88 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
# from functions import get_todos and write_todos
import functions
import time
now = time.strftime("%b %d %Y %H:%M:%S")
print("It is ",now)
while True:
# Getting user input and strip the blank spaces after it
a = input( "Type add/show/edit/exit/complete : ")
user_action = a.strip()
if user_action.startswith("add") :
todo = user_action[4:] + '\n'
todos = functions.get_todos()
todos.append(todo)
functions.write_todos(todos)
elif user_action.startswith("show") :
todos = functions.get_todos()
for index,element in enumerate(todos):
print(f"{index+1}-{element.strip()}")
elif user_action.startswith("edit") :
try:
n = int(user_action[5:])
todos = functions.get_todos()
print("Existing todo is: ",(todos[n-1]).split())
a = input("Enter a new Todo:")
todos[n-1] = a+ '\n'
functions.write_todos(todos)
except ValueError:
print("Your Command is not valid!")
continue
elif user_action.startswith("complete") :
try:
n = int(user_action[9:])
todos = functions.get_todos()
index = n-1
todo_completed = todos[index].strip('\n')
todos.pop(index)
functions.write_todos(todos)
m = f"Todo {todo_completed} was removed from the list."
print(m)
except IndexError:
print("There is no itme with that number.")
continue
# exiting the loop
elif user_action.startswith("exit") :
break
# when user entered any other input
else:
print("You entered a wrong command !")
print("........Thank You!......")