app.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """
  2. 期货数据管理系统入口文件
  3. """
  4. from app import create_app
  5. import os
  6. from app.database.schema import create_schemas
  7. import logging
  8. app = create_app()
  9. if __name__ == '__main__':
  10. # 设置数据库文件路径
  11. data_dir = os.path.join(os.getcwd(), "data")
  12. if not os.path.exists(data_dir):
  13. os.makedirs(data_dir, exist_ok=True)
  14. app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(data_dir, "financial_tools.db")}'
  15. # 确保表结构存在
  16. create_schemas(app)
  17. print("数据库表结构已验证!")
  18. # 从配置服务读取服务器配置参数
  19. try:
  20. from app.services.config_service import get_str_config, get_int_config, get_bool_config
  21. # 配置日志级别(支持热更新)
  22. log_level_str = get_str_config('log_level', 'DEBUG')
  23. log_level = getattr(logging, log_level_str.upper(), logging.DEBUG)
  24. logging.basicConfig(
  25. level=log_level,
  26. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  27. force=True # 强制重新配置
  28. )
  29. print(f"日志级别已设置为: {log_level_str}")
  30. # 服务器配置(需重启生效)
  31. app_host = get_str_config('app_host', '0.0.0.0')
  32. app_port = get_int_config('app_port', 4950)
  33. debug_mode = get_bool_config('debug_mode', True)
  34. print(f"服务器配置: host={app_host}, port={app_port}, debug={debug_mode}")
  35. app.run(debug=debug_mode, host=app_host, port=app_port)
  36. except Exception as e:
  37. # 如果配置服务出错,使用默认配置
  38. print(f"配置服务获取失败,使用默认配置: {e}")
  39. logging.basicConfig(
  40. level=logging.DEBUG,
  41. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
  42. )
  43. app.run(debug=True, host='0.0.0.0', port=4950)