settings.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. from dotenv import load_dotenv
  3. import logging
  4. from httpx import get
  5. # Load environment variables from .env file
  6. load_dotenv()
  7. APPNAME = "Pedidos Express"
  8. LOGS_FOLDER = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
  9. if not os.path.exists(LOGS_FOLDER):
  10. os.makedirs(LOGS_FOLDER)
  11. LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
  12. # Configure logging
  13. logging.basicConfig(
  14. level=getattr(logging, LOG_LEVEL),
  15. format='%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s',
  16. handlers=[
  17. logging.FileHandler(os.path.join(LOGS_FOLDER, 'app.log')),
  18. logging.StreamHandler()
  19. ]
  20. )
  21. # Configuration
  22. OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
  23. PORT = int(os.getenv("PORT", 6001))
  24. PIN_KEY = os.getenv("PIN_KEY", "-1")
  25. if PIN_KEY == "-1":
  26. logging.warning("Using default PIN_KEY. Please set a strong PIN_KEY in your .env file for production.")
  27. # SECRET_KEY is crucial for signing session cookies.
  28. # Fallback to a default if not set, but warn that this is insecure for production.
  29. SECRET_KEY = os.getenv("SECRET_KEY", "your_very_very_secret_key_for_signing_cookies_python_v2")
  30. # Data paths
  31. BG_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),'data', 'llm_data.json')
  32. PRODUCT_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),'data', 'products.json')
  33. DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),'data', 'data.db')
  34. def validate_config():
  35. logger = logging.getLogger(__name__)
  36. """Validate configuration and show warnings"""
  37. if SECRET_KEY == "your_very_very_secret_key_for_signing_cookies_python_v2":
  38. logger.warning("Using default SECRET_KEY. Please set a strong SECRET_KEY in your .env file for production.")
  39. if not OPENAI_API_KEY:
  40. logger.critical("CRITICAL ERROR: OPENAI_API_KEY environment variable not set. The application will not work correctly.")
  41. return False
  42. return True