config.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from pathlib import Path
  2. from typing import Dict, List
  3. from enum import Enum
  4. import json
  5. class Settings:
  6. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  7. CONFIG_PATH = BASE_PATH / 'Config.json'
  8. API_PREFIX: str = "/api" # 通用前缀
  9. DATA_DIR = BASE_PATH / "Data"
  10. SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
  11. # 分数计算接口url
  12. SCORE_UPDATE_SERVER_URL = "http://127.0.0.1:7744"
  13. SCORE_RECALCULATE_ENDPOINT = f"{SCORE_UPDATE_SERVER_URL}/api/card_score/score_recalculate"
  14. # --- 数据库配置 ---
  15. DB_NAME = 'card_score_database'
  16. # 从 Config.json 读取的旧表名, 我们将不再使用它, 但保留以兼容旧文件
  17. # 建议直接在代码中定义新表名, 避免混淆
  18. DB_CARD_TABLE_NAME = 'cards'
  19. DB_IMAGE_TABLE_NAME = 'card_images' # 新的图片表名
  20. DATABASE_CONFIG: Dict[str, str] = {
  21. 'user': 'root',
  22. 'password': '123456',
  23. 'host': '127.0.0.1',
  24. }
  25. # 连接到指定数据库的配置
  26. DATABASE_CONFIG_WITH_DB: Dict[str, str] = {
  27. **DATABASE_CONFIG,
  28. 'database': DB_NAME
  29. }
  30. def set_config(self):
  31. with open(self.CONFIG_PATH, 'r') as f:
  32. config_json = json.load(f)
  33. self.DATABASE_CONFIG = config_json["mysql_config"]
  34. self.DB_NAME = config_json["database_name"]
  35. settings = Settings()
  36. print(f"项目根目录: {settings.BASE_PATH}")
  37. print(f"数据存储目录: {settings.DATA_DIR}")