-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
76 lines (53 loc) · 2.11 KB
/
cli.py
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
import functions
import time
now = time.strftime("%b %d, %Y %H:%M:%S")
print("Es", now)
while True:
user_action = input("Escriba agregar, mostrar, editar, completada o salir: ")
user_action = user_action.strip().lower()
if user_action.startswith('agregar'):
user_task = user_action[8:]
print(user_task)
tasks = functions.get_tasks()
tasks.append(user_task + "\n")
functions.write_tasks(tasks)
elif user_action.startswith('mostrar'):
tasks = functions.get_tasks()
# new_tasks = []
# for task in tasks:
# new_task = task.strip("\n")
# new_tasks.append(new_task)
# new_tasks = [task.strip("\n") for task in tasks]
for index, task in enumerate(tasks):
task = task.strip("\n")
chain = f"{index + 1}-{task}"
print(chain)
elif user_action.startswith('editar'):
try:
number = int(user_action[7:])
number -= 1
tasks = functions.get_tasks()
new_task = input(f"Edite la tarea: ")
tasks[number] = new_task + "\n"
functions.write_tasks(tasks)
except ValueError:
print("Indique el número de la tarea a editar seguido del comando 'editar'.")
continue
elif user_action.startswith('completada'):
try:
number = int(user_action[10:])
tasks = functions.get_tasks()
index = number - 1
task_to_remove = tasks[index].strip("\n")
tasks.pop(index)
functions.write_tasks(tasks)
message = f"La tarea '{task_to_remove}' fue removida"
print(message)
except IndexError:
print("No hay un artículo con ese número.")
continue
elif user_action.startswith('salir'):
break
else:
print("Comando inválido")
print("El programa terminó!")