-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
80 lines (59 loc) · 2.08 KB
/
Copy pathcli.py
File metadata and controls
80 lines (59 loc) · 2.08 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
#from functions import get_todos, write_todos
from modules import functions
import time
now = time.strftime("%b %d, %Y %H:%M:%S")
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)
elif user_action.startswith("show"):
todos = functions.get_todos()
for index, item in enumerate(todos):
#striping the "\n" without any method
item = item.strip('\n')
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)
except ValueError:
print("Your command is not valid.")
continue
elif user_action.startswith("complete"):
try:
number = int(user_action[9:])
todos = functions.get_todos()
index = number - 1
todo_to_remove = todos[number-1].strip('\n')
todos.pop(index)
functions.write_todos(todos)
message = f"todo {todo_to_remove} was removed from the list."
print(message)
except IndexError:
print("There is no item with that number.")
continue
except ValueError:
print("to complete an item you should type it's index.")
continue
elif user_action.startswith("exit"):
print(f"Pending items:")
for index, item in enumerate(todos):
#striping the "\n" without any method
item = item.strip('\n')
row = f"{index + 1} - {item}"
print(row)
break
else:
print('Comand is not valid')
print("Bye")