30 lines
1008 B
Python
30 lines
1008 B
Python
"""
|
|
backend/app/services/faq_hot_settings.py
|
|
|
|
用途:读取热点 FAQ 离线聚合环境变量(权威默认值在仓库根 `.env.shared`)。
|
|
依赖:os.environ(由 config._load_environment_files 在启动时加载)。
|
|
逻辑:hot_faq_aggregator、hot_faq_candidate_store 通过本模块读配置,不经过 config.py。
|
|
"""
|
|
import os
|
|
from typing import Any
|
|
|
|
|
|
def read_faq_hot_env(key: str, default: Any) -> Any:
|
|
"""
|
|
读取单个 FAQ_HOT_* 环境变量并按 default 类型转换。
|
|
@param key - 环境变量名,如 FAQ_HOT_WINDOW_DAYS
|
|
@param default - 未配置时的兜底值,同时决定返回类型
|
|
@returns 转换后的配置值
|
|
"""
|
|
raw = os.getenv(key)
|
|
if raw is None or str(raw).strip() == '':
|
|
return default
|
|
text = str(raw).strip()
|
|
if isinstance(default, bool):
|
|
return text.lower() == 'true'
|
|
if isinstance(default, float):
|
|
return float(text)
|
|
if isinstance(default, int):
|
|
return int(text)
|
|
return text
|