-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
75 lines (47 loc) · 1.68 KB
/
cli.py
File metadata and controls
75 lines (47 loc) · 1.68 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
import functions
import time
now = time.strftime("%m/%d/%Y %I:%M:%S %p")
print("It is", now)
while True:
user_action = input("Type add, show, edit, complete or exit:")
user_action = user_action.strip()
if user_action.startswith("add"):
todo = user_action[4:]
todos = functions.get_todos()
todos.append(todo + "\n")
functions.write_todos(todos,"todos.txt")
elif user_action.startswith("show"):
todos = functions.get_todos()
new_todos = [item.strip("\n") for item in todos]
for index, item in enumerate(new_todos):
row = f"{index + 1}-{item}"
print(row)
elif user_action.startswith("edit"):
try:
number = int(user_action[5:])
print(number)
number = number - 1
todos = functions.get_todos()
new_todo = input("enter new todo:")
todos[number] = new_todo + "\n"
functions.write_todos(todos, "todos.txt")
except ValueError:
print("That ain't right(the command)")
continue
elif user_action.startswith("complete"):
try:
number = int(user_action[9:])
todos = functions.get_todos()
index = number - 1
todo_to_remove = todos[index].strip("\n")
todos.pop(index)
functions.write_todos(todos, "todos.txt")
message = f"Todo {todo_to_remove} was removed from the list."
print(message)
except IndexError:
print("no item with that number")
elif user_action.startswith("exit"):
break
else:
print("invalid input")
print("Byeeee Queen")