forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
76 lines (63 loc) · 2.32 KB
/
mouredev.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
76
import logging
import time
"""
Ejercicio
"""
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[logging.StreamHandler()])
logging.debug("Esto es un mensaje de DEBUG")
logging.info("Esto es un mensaje de INFO")
logging.warning("Esto es un mensaje de WARNING")
logging.error("Esto es un mensaje de ERROR")
logging.critical("Esto es un mensaje de CRITICAL")
"""
Extra
"""
class TaskManager:
def __init__(self) -> None:
self.tasks = {}
def add_task(self, name: str, description: str):
start_time = time.time()
if name not in self.tasks:
self.tasks[name] = description
logging.info(f"Tarea añadida: {name}.")
else:
logging.warning(
f"Se ha intentado añadir una tarea que ya existe: {name}.")
logging.debug(f"Número de tareas: {len(self.tasks)}")
end_time = time.time()
self._print_time(start_time, end_time)
def delete_task(self, name: str):
start_time = time.time()
if name in self.tasks:
del self.tasks[name]
logging.info(f"Se ha eliminado la tarea: {name}.")
else:
logging.error(
f"Se ha intentado eliminar una tarea que no existe: {name}.")
logging.debug(f"Número de tareas: {len(self.tasks)}")
end_time = time.time()
self._print_time(start_time, end_time)
def list_tasks(self):
start_time = time.time()
if self.tasks:
logging.info(f"Se va a imprimir la lista de tareas.")
for name, description in self.tasks.items():
print(f"{name} - {description}")
else:
logging.info("No hay tareas para mostrar.")
end_time = time.time()
self._print_time(start_time, end_time)
def _print_time(self, start_time, end_time):
logging.debug(
f"Tiempo de ejecución: {end_time - start_time:.6f} segundos.")
task_manager = TaskManager()
task_manager.list_tasks()
task_manager.add_task("Pan", "Comprar 5 barras de pan")
task_manager.add_task("Python", "Estudiar Python")
task_manager.list_tasks()
task_manager.delete_task("Python")
task_manager.list_tasks()
task_manager.add_task("Pan", "Comprar 5 barras de pan")
task_manager.delete_task("Python")