-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
71 lines (46 loc) · 1.54 KB
/
Copy pathcli.py
File metadata and controls
71 lines (46 loc) · 1.54 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
from functions import get_todos, write_todos
import time
now = time.strftime("%B %d, %Y %I:%M%p")
print("The time is below: ")
print("It is",now)
while True:
#Get user input and strip space chars
user_action = input('Type add, show, edit, complete, or exit: ')
user_action = user_action.strip()
#Check users action
if user_action.startswith('add'):
todo = user_action[4:]
todos = get_todos()
todos.append(todo + '\n')
write_todos(todos)
elif user_action.startswith('show'):
todos = get_todos()
for index,item in enumerate(todos):
item = item.strip('\n')
row = f"{index + 1}) {item}"
print(row)
elif user_action.startswith('complete'):
number = int(user_action[9:])
todos = get_todos("todos.txt")
index = number -1
todos_removed = todos[index].strip("\n")
todos.pop(index)
write_todos(todos)
print(f"Todo {todos_removed} was removed from the list.")
elif user_action.startswith('edit'):
try:
number = int(user_action[5:])
print(number)
number -= 1
todos = get_todos()
new_todo = input('Enter new todo: ')
todos[number] = new_todo + '\n'
write_todos(todos)
except ValueError:
print("Your command is not valid.")
continue
elif user_action.startswith('exit'):
break
else:
print("Command is not valid.")
print('Bye')