Skip to content

⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。

fix(config): 修复环境变量设为 0 时被 or 真值判断静默忽略的问题

sansan07c5bcbea80a
diff --git a/trendradar/core/loader.py b/trendradar/core/loader.py
index 03b1ad114e..49e83918a1 100644
--- a/trendradar/core/loader.py
+++ b/trendradar/core/loader.py
@@ -23,17 +23,6 @@ def _get_env_bool(key: str) -> Optional[bool]:
return value in ("true", "1")
-def _get_env_int(key: str, default: int = 0) -> int:
- """从环境变量获取整数值"""
- value = os.environ.get(key, "").strip()
- if not value:
- return default
- try:
- return int(value)
- except ValueError:
- return default
-
-
def _get_env_int_or_none(key: str) -> Optional[int]:
"""从环境变量获取整数值,未设置时返回 None"""
value = os.environ.get(key, "").strip()
@@ -83,14 +72,14 @@ def _load_report_config(config_data: Dict) -> Dict:
# 环境变量覆盖
sort_by_position_env = _get_env_bool("SORT_BY_POSITION_FIRST")
- max_news_env = _get_env_int("MAX_NEWS_PER_KEYWORD")
+ max_news_env = _get_env_int_or_none("MAX_NEWS_PER_KEYWORD")
return {
"REPORT_MODE": report_config.get("mode", "daily"),
"DISPLAY_MODE": report_config.get("display_mode", "keyword"),
"RANK_THRESHOLD": report_config.get("rank_threshold", 10),
"SORT_BY_POSITION_FIRST": sort_by_position_env if sort_by_position_env is not None else report_config.get("sort_by_position_first", False),
- "MAX_NEWS_PER_KEYWORD": max_news_env or report_config.get("max_news_per_keyword", 0),
+ "MAX_NEWS_PER_KEYWORD": max_news_env if max_news_env is not None else report_config.get("max_news_per_keyword", 0),
}
@@ -100,6 +89,8 @@ def _load_notification_config(config_data: Dict) -> Dict:
advanced = config_data.get("advanced", {})
batch_size = advanced.get("batch_size", {})
+ max_accounts_env = _get_env_int_or_none("MAX_ACCOUNTS_PER_CHANNEL")
+
return {
"ENABLE_NOTIFICATION": notification.get("enabled", True),
"MESSAGE_BATCH_SIZE": batch_size.get("default", 4000),
@@ -109,7 +100,7 @@ def _load_notification_config(config_data: Dict) -> Dict:
"SLACK_BATCH_SIZE": batch_size.get("slack", 4000),
"BATCH_SEND_INTERVAL": advanced.get("batch_send_interval", 1.0),
"FEISHU_MESSAGE_SEPARATOR": advanced.get("feishu_message_separator", "---"),
- "MAX_ACCOUNTS_PER_CHANNEL": _get_env_int("MAX_ACCOUNTS_PER_CHANNEL") or advanced.get("max_accounts_per_channel", 3),
+ "MAX_ACCOUNTS_PER_CHANNEL": max_accounts_env if max_accounts_env is not None else advanced.get("max_accounts_per_channel", 3),
}
@@ -371,6 +362,9 @@ def _load_storage_config(config_data: Dict) -> Dict:
txt_enabled_env = _get_env_bool("STORAGE_TXT_ENABLED")
html_enabled_env = _get_env_bool("STORAGE_HTML_ENABLED")
pull_enabled_env = _get_env_bool("PULL_ENABLED")
+ local_retention_env = _get_env_int_or_none("LOCAL_RETENTION_DAYS")
+ remote_retention_env = _get_env_int_or_none("REMOTE_RETENTION_DAYS")
+ pull_days_env = _get_env_int_or_none("PULL_DAYS")
return {
"BACKEND": _get_env_str("STORAGE_BACKEND") or storage.get("backend", "auto"),
@@ -381,7 +375,7 @@ def _load_storage_config(config_data: Dict) -> Dict:
},
"LOCAL": {
"DATA_DIR": local.get("data_dir", "output"),
- "RETENTION_DAYS": _get_env_int("LOCAL_RETENTION_DAYS") or local.get("retention_days", 0),
+ "RETENTION_DAYS": local_retention_env if local_retention_env is not None else local.get("retention_days", 0),
},
"REMOTE": {
"ENDPOINT_URL": _get_env_str("S3_ENDPOINT_URL") or remote.get("endpoint_url", ""),
@@ -389,11 +383,11 @@ def _load_storage_config(config_data: Dict) -> Dict:
"ACCESS_KEY_ID": _get_env_str("S3_ACCESS_KEY_ID") or remote.get("access_key_id", ""),
"SECRET_ACCESS_KEY": _get_env_str("S3_SECRET_ACCESS_KEY") or remote.get("secret_access_key", ""),
"REGION": _get_env_str("S3_REGION") or remote.get("region", ""),
- "RETENTION_DAYS": _get_env_int("REMOTE_RETENTION_DAYS") or remote.get("retention_days", 0),
+ "RETENTION_DAYS": remote_retention_env if remote_retention_env is not None else remote.get("retention_days", 0),
},
"PULL": {
"ENABLED": pull_enabled_env if pull_enabled_env is not None else pull.get("enabled", False),
- "DAYS": _get_env_int("PULL_DAYS") or pull.get("days", 7),
+ "DAYS": pull_days_env if pull_days_env is not None else pull.get("days", 7),
},
}