From 7acfbc4b1df68e665f324ab861c31fb82db5bca5 Mon Sep 17 00:00:00 2001 From: Santiago Date: Fri, 15 Dec 2023 15:30:24 +0100 Subject: [PATCH] Agreganto carpeta MenuRestaurante --- MenuRestaurante/Menu.py | 45 ++++++++++++++++++++++++++++++++++++ MenuRestaurante/menu.txt | 13 +++++++++++ MenuRestaurante/postres.txt | 1 + MenuRestaurante/primeros.txt | 10 ++++++++ MenuRestaurante/segundos.txt | 6 +++++ 5 files changed, 75 insertions(+) create mode 100644 MenuRestaurante/Menu.py create mode 100644 MenuRestaurante/menu.txt create mode 100644 MenuRestaurante/postres.txt create mode 100644 MenuRestaurante/primeros.txt create mode 100644 MenuRestaurante/segundos.txt diff --git a/MenuRestaurante/Menu.py b/MenuRestaurante/Menu.py new file mode 100644 index 0000000..00474a8 --- /dev/null +++ b/MenuRestaurante/Menu.py @@ -0,0 +1,45 @@ +import threading + +def leer_menu(tipo, archivo_entrada, archivo_salida): + try: + with open(archivo_entrada, 'r') as f: + lineas = f.readlines() + in_section = False + items = [] + + for linea in lineas: + if linea.startswith(f"{tipo}-"): + in_section = True + continue + elif in_section and linea.strip() == "": + in_section = False + continue + + if in_section: + # Eliminar el número y guion del principio y agregar al resultado + plato = linea.strip()[len(f"{tipo}-"):] + items.append(plato) + print(f"El hilo {tipo} está escribiendo ... {plato}") + + with open(archivo_salida, 'w') as f: + f.write('\n'.join(items)) + + except Exception as e: + print(f"Error: {e}") + +# Crear los hilos +hilo_primeros = threading.Thread(target=leer_menu, args=(1, 'MenuRestaurante/menu.txt', 'MenuRestaurante/primeros.txt')) +hilo_segundos = threading.Thread(target=leer_menu, args=(2, 'MenuRestaurante/menu.txt', 'MenuRestaurante/segundos.txt')) +hilo_postres = threading.Thread(target=leer_menu, args=(3, 'MenuRestaurante/menu.txt', 'MenuRestaurante/postres.txt')) + +# Iniciar los hilos +hilo_primeros.start() +hilo_segundos.start() +hilo_postres.start() + +# Esperar a que todos los hilos terminen +hilo_primeros.join() +hilo_segundos.join() +hilo_postres.join() + +print("Proceso completado.") diff --git a/MenuRestaurante/menu.txt b/MenuRestaurante/menu.txt new file mode 100644 index 0000000..39fdabf --- /dev/null +++ b/MenuRestaurante/menu.txt @@ -0,0 +1,13 @@ +1-PRIMEROS +1-Macarrones con tomate +1-Paella valenciana +... +2-SEGUNDOS +2-Cachopo asturiano +2-Chuletón gallego +... +3-POSTRES +3-Fruta del tiempo +3-Tarta de manzana +3-Cuajada con miel +... diff --git a/MenuRestaurante/postres.txt b/MenuRestaurante/postres.txt new file mode 100644 index 0000000..945c9b4 --- /dev/null +++ b/MenuRestaurante/postres.txt @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/MenuRestaurante/primeros.txt b/MenuRestaurante/primeros.txt new file mode 100644 index 0000000..ff4fa11 --- /dev/null +++ b/MenuRestaurante/primeros.txt @@ -0,0 +1,10 @@ +. +SEGUNDOS +Cachopo asturiano +Chuletón gallego +. +POSTRES +Fruta del tiempo +Tarta de manzana +Cuajada con miel +. \ No newline at end of file diff --git a/MenuRestaurante/segundos.txt b/MenuRestaurante/segundos.txt new file mode 100644 index 0000000..ecb5842 --- /dev/null +++ b/MenuRestaurante/segundos.txt @@ -0,0 +1,6 @@ +. +POSTRES +Fruta del tiempo +Tarta de manzana +Cuajada con miel +. \ No newline at end of file