main.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import asyncio
  2. import os
  3. import uvicorn
  4. from app import create_app, setup_routes
  5. from config.settings import PORT, OPENAI_API_KEY, BG_DATA_PATH, validate_config
  6. from logging import getLogger
  7. from routes.orders import order_thread
  8. from threading import Thread
  9. from services.data_service import initialize_db
  10. logger = getLogger("main")
  11. def main():
  12. """Main application entry point"""
  13. # Validate configuration
  14. if not validate_config():
  15. logger.critical("FATAL: Configuration validation failed.")
  16. if not OPENAI_API_KEY:
  17. logger.error("Please create a .env file with OPENAI_API_KEY='your_key_here'")
  18. with open(".env", "w") as f:
  19. f.write("OPENAI_API_KEY='your_key_here'")
  20. return
  21. # Create and configure app
  22. app = create_app()
  23. setup_routes(app)
  24. initialize_db()
  25. # Display startup information
  26. logger.info(f"Servidor corriendo en http://localhost:{PORT}")
  27. if not os.path.exists(BG_DATA_PATH):
  28. logger.warning(f"ADVERTENCIA: {BG_DATA_PATH} no encontrado. El asistente de IA no tendrá datos específicos del menú.")
  29. else:
  30. logger.info(f"Datos del asistente cargados desde: {os.path.abspath(BG_DATA_PATH)}")
  31. # Run the threads
  32. thread = Thread(target=order_thread, daemon=True)
  33. thread.start()
  34. # Start the server
  35. #rut without logs
  36. uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info", access_log=False)
  37. if __name__ == "__main__":
  38. main()