import os
# 1. Definimos la estructura exacta
estructura = {
"hotel/__init__.py": "",
"hotel/habitaciones/__init__.py": "",
"hotel/pagos/__init__.py": "",
"hotel/habitaciones/gestion.py": '''
import json, os
ARCHIVO = "hotel_data.json"
habitaciones = {"101": ["Sencilla", 50, True], "201": ["Doble", 80, True]}
def cargar():
global habitaciones
if os.path.exists(ARCHIVO):
with open(ARCHIVO, "r") as f: habitaciones = json.load(f)
def guardar():
with open(ARCHIVO, "w") as f: json.dump(habitaciones, f, indent=4)
def mostrar():
cargar()
for k, v in habitaciones.items():
print(f"Hab {k} [{v[0]}] - ${v[1]} | {'✅' if v[2] else '❌'}")
def reservar(num):
if str(num) in habitaciones and habitaciones[str(num)][2]:
habitaciones[str(num)][2] = False
guardar()
return True
return False
def liberar(num):
if str(num) in habitaciones and not habitaciones[str(num)][2]:
habitaciones[str(num)][2] = True
guardar()
return True
return False
''',
"hotel/pagos/procesar.py": "def pagar(m): print(f'💰 Pago de ${m} procesado.')",
"main.py": '''
import sys, os
# FORZAR RUTA: Esto hace que Python encuentre la carpeta 'hotel'
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from hotel.habitaciones.gestion import mostrar, reservar, liberar
from hotel.pagos.procesar import pagar
def menu():
while True:
print("\\n--- HOTEL DE SAUL-----")
print("1. Ver | 2. Reservar | 3. Liberar | 4. Salir")
op = input("Seleccione: ")
if op == "1": mostrar()
elif op == "2":
n = input("Habitación: ")
if reservar(n): pagar(50); print("✅ Hecho")
else: print("❌ Error")
elif op == "3":
n = input("Habitación: ")
if liberar(n): print("✅ Liberada")
else: print("❌ Estaba libre")
elif op == "4": break
if __name__ == "__main__": menu()
'''
}
# 2. Crear las carpetas y archivos
for ruta, contenido in estructura.items():
directorio = os.path.dirname(ruta)
if directorio: os.makedirs(directorio, exist_ok=True)
with open(ruta, "w", encoding="utf-8") as f:
f.write(contenido.strip())
print("✅ ESTRUCTURA CREADA. Ahora ejecuta: python main.py")