import asyncio import os import uvicorn from app import create_app, setup_routes from config.settings import PORT, OPENAI_API_KEY, BG_DATA_PATH, validate_config from logging import getLogger from routes.orders import order_thread from threading import Thread from services.data_service import initialize_db logger = getLogger("main") def main(): """Main application entry point""" # Validate configuration if not validate_config(): logger.critical("FATAL: Configuration validation failed.") if not OPENAI_API_KEY: logger.error("Please create a .env file with OPENAI_API_KEY='your_key_here'") with open(".env", "w") as f: f.write("OPENAI_API_KEY='your_key_here'") return # Create and configure app app = create_app() setup_routes(app) initialize_db() # Display startup information logger.info(f"Servidor corriendo en http://localhost:{PORT}") if not os.path.exists(BG_DATA_PATH): logger.warning(f"ADVERTENCIA: {BG_DATA_PATH} no encontrado. El asistente de IA no tendrá datos específicos del menú.") else: logger.info(f"Datos del asistente cargados desde: {os.path.abspath(BG_DATA_PATH)}") # Run the threads thread = Thread(target=order_thread, daemon=True) thread.start() # Start the server #rut without logs uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info", access_log=False) if __name__ == "__main__": main()