修复bug

This commit is contained in:
wood chen 2025-02-23 00:29:07 +08:00
parent 857dd3a0cd
commit c39781d4dc
2 changed files with 17 additions and 3 deletions

View File

@ -18,7 +18,7 @@ COPY main.py .
RUN pip install -r requirements.txt
# 创建配置文件和日志目录
RUN mkdir -p logs && touch .env
RUN mkdir -p logs && touch config.yaml
# 运行程序
CMD ["python", "main.py"]

View File

@ -1,6 +1,7 @@
import os
from typing import Dict, List
import yaml
from loguru import logger
# 加载YAML配置
def load_config() -> Dict:
@ -8,8 +9,21 @@ def load_config() -> Dict:
yaml_files = ["config.yaml", "config.example.yaml"]
for yaml_file in yaml_files:
if os.path.exists(yaml_file):
try:
with open(yaml_file, "r", encoding="utf-8") as f:
return yaml.safe_load(f)
config = yaml.safe_load(f)
logger.info(f"成功加载配置文件: {yaml_file}")
# 验证必要的配置项
if not config.get("tencent", {}).get("secret_id"):
logger.error(f"配置文件 {yaml_file} 中缺少必要的配置项: tencent.secret_id")
return {}
if not config.get("tencent", {}).get("secret_key"):
logger.error(f"配置文件 {yaml_file} 中缺少必要的配置项: tencent.secret_key")
return {}
return config
except Exception as e:
logger.error(f"加载配置文件 {yaml_file} 失败: {str(e)}")
logger.error("未找到有效的配置文件")
return {}
# 加载配置