""" 期货数据管理系统入口文件 """ from app import create_app import os from app.database.schema import create_schemas import logging app = create_app() if __name__ == '__main__': # 设置数据库文件路径 data_dir = os.path.join(os.getcwd(), "data") if not os.path.exists(data_dir): os.makedirs(data_dir, exist_ok=True) app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(data_dir, "financial_tools.db")}' # 确保表结构存在 create_schemas(app) print("数据库表结构已验证!") # 从配置服务读取服务器配置参数 try: from app.services.config_service import get_str_config, get_int_config, get_bool_config # 配置日志级别(支持热更新) log_level_str = get_str_config('log_level', 'DEBUG') log_level = getattr(logging, log_level_str.upper(), logging.DEBUG) logging.basicConfig( level=log_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', force=True # 强制重新配置 ) print(f"日志级别已设置为: {log_level_str}") # 服务器配置(需重启生效) app_host = get_str_config('app_host', '0.0.0.0') app_port = get_int_config('app_port', 4950) debug_mode = get_bool_config('debug_mode', True) print(f"服务器配置: host={app_host}, port={app_port}, debug={debug_mode}") app.run(debug=debug_mode, host=app_host, port=app_port) except Exception as e: # 如果配置服务出错,使用默认配置 print(f"配置服务获取失败,使用默认配置: {e}") logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) app.run(debug=True, host='0.0.0.0', port=4950)