-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
90 lines (69 loc) · 2.77 KB
/
cli.py
File metadata and controls
90 lines (69 loc) · 2.77 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
81
82
83
84
85
86
87
88
89
90
# Main file for app1
# from functions import get_todos, write_todos
import functions
import time
while True:
# print("Here's your list: ")
# new_todos = [item.strip('\n') for item in todos]
#
# for index, item in enumerate(new_todos):
# print(f"{index + 1}. {item}")
print("The time is: ", time.strftime("%b %d, %Y %H:%M:%S"))
user_action = input("Type save, add, view, edit, complete, or exit: ")
if user_action.startswith('add'):
# list slicing operation, as a range, from x : to y
todo = user_action[4:]
# todo = input("Enter a To-Do Item: ") + "\n"
todos = functions.get_todos()
todos.append(todo + '\n')
functions.write_todos(todos, )
print(f"{todo} was added!")
elif user_action.startswith('view'):
print("Here's your list: ")
todos = functions.get_todos()
# METHOD 1: remove formatting via for loop and strip function
# new_todos = []
# for item in todos:
# new_item = item.strip('\n')
# new_todos.append(new_item)
# METHOD 2: list comprehension [do action for each iteration]
new_todos = [item.strip('\n') for item in todos]
for index, item in enumerate(new_todos):
print(f"{index + 1}. {item}")
elif user_action.startswith('edit'):
todos = functions.get_todos()
try:
number = int(user_action[5:])
# for index, item in enumerate(todos):
# item = item.strip('\n')
# print(f"{index + 1}. {item}")
# number = int(input("Enter the Item Number: "))
print(f"You selected: {str(number)}. {todos[int(number - 1)]}")
new_todo = input("Enter revision: ") + "\n"
todos[number - 1] = new_todo
functions.write_todos(todos, )
print("Update complete!", todos)
except ValueError:
print("Your command was not recognized. ")
continue
elif user_action.startswith('complete'):
todos = functions.get_todos()
try:
number = int(user_action[9:])
# for index, item in enumerate(todos):
# item = item.strip('\n')
# print(f"{index + 1}. {item}")
# number = int(input("Enter the Item Number you Completed: "))
index = number - 1
todo_last_remove = todos[index].strip('\n')
todos.pop(index)
functions.write_todos(todos, )
print(f"Removed '{todo_last_remove}'. Nice job!")
except IndexError:
print("There is no item in that range. ")
continue
elif user_action.startswith('exit'):
break
else:
print("Command not detected. Please try again. ")
print("Bye!")