mirror of
https://gitee.com/houhuan/TrendRadar.git
synced 2025-12-21 14:27:15 +08:00
v2.3.2
This commit is contained in:
parent
9932fee001
commit
e5835eca58
53
main.py
53
main.py
@ -20,7 +20,7 @@ import requests
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
VERSION = "2.3.1"
|
VERSION = "2.3.2"
|
||||||
|
|
||||||
|
|
||||||
# === SMTP邮件配置 ===
|
# === SMTP邮件配置 ===
|
||||||
@ -142,7 +142,7 @@ def load_config():
|
|||||||
"PLATFORMS": config_data["platforms"],
|
"PLATFORMS": config_data["platforms"],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Webhook配置(环境变量优先)
|
# 通知渠道配置(环境变量优先)
|
||||||
notification = config_data.get("notification", {})
|
notification = config_data.get("notification", {})
|
||||||
webhooks = notification.get("webhooks", {})
|
webhooks = notification.get("webhooks", {})
|
||||||
|
|
||||||
@ -180,30 +180,30 @@ def load_config():
|
|||||||
).strip() or webhooks.get("email_smtp_port", "")
|
).strip() or webhooks.get("email_smtp_port", "")
|
||||||
|
|
||||||
# 输出配置来源信息
|
# 输出配置来源信息
|
||||||
webhook_sources = []
|
notification_sources = []
|
||||||
if config["FEISHU_WEBHOOK_URL"]:
|
if config["FEISHU_WEBHOOK_URL"]:
|
||||||
source = "环境变量" if os.environ.get("FEISHU_WEBHOOK_URL") else "配置文件"
|
source = "环境变量" if os.environ.get("FEISHU_WEBHOOK_URL") else "配置文件"
|
||||||
webhook_sources.append(f"飞书({source})")
|
notification_sources.append(f"飞书({source})")
|
||||||
if config["DINGTALK_WEBHOOK_URL"]:
|
if config["DINGTALK_WEBHOOK_URL"]:
|
||||||
source = "环境变量" if os.environ.get("DINGTALK_WEBHOOK_URL") else "配置文件"
|
source = "环境变量" if os.environ.get("DINGTALK_WEBHOOK_URL") else "配置文件"
|
||||||
webhook_sources.append(f"钉钉({source})")
|
notification_sources.append(f"钉钉({source})")
|
||||||
if config["WEWORK_WEBHOOK_URL"]:
|
if config["WEWORK_WEBHOOK_URL"]:
|
||||||
source = "环境变量" if os.environ.get("WEWORK_WEBHOOK_URL") else "配置文件"
|
source = "环境变量" if os.environ.get("WEWORK_WEBHOOK_URL") else "配置文件"
|
||||||
webhook_sources.append(f"企业微信({source})")
|
notification_sources.append(f"企业微信({source})")
|
||||||
if config["TELEGRAM_BOT_TOKEN"] and config["TELEGRAM_CHAT_ID"]:
|
if config["TELEGRAM_BOT_TOKEN"] and config["TELEGRAM_CHAT_ID"]:
|
||||||
token_source = (
|
token_source = (
|
||||||
"环境变量" if os.environ.get("TELEGRAM_BOT_TOKEN") else "配置文件"
|
"环境变量" if os.environ.get("TELEGRAM_BOT_TOKEN") else "配置文件"
|
||||||
)
|
)
|
||||||
chat_source = "环境变量" if os.environ.get("TELEGRAM_CHAT_ID") else "配置文件"
|
chat_source = "环境变量" if os.environ.get("TELEGRAM_CHAT_ID") else "配置文件"
|
||||||
webhook_sources.append(f"Telegram({token_source}/{chat_source})")
|
notification_sources.append(f"Telegram({token_source}/{chat_source})")
|
||||||
if config["EMAIL_FROM"] and config["EMAIL_PASSWORD"] and config["EMAIL_TO"]:
|
if config["EMAIL_FROM"] and config["EMAIL_PASSWORD"] and config["EMAIL_TO"]:
|
||||||
from_source = "环境变量" if os.environ.get("EMAIL_FROM") else "配置文件"
|
from_source = "环境变量" if os.environ.get("EMAIL_FROM") else "配置文件"
|
||||||
webhook_sources.append(f"邮件({from_source})")
|
notification_sources.append(f"邮件({from_source})")
|
||||||
|
|
||||||
if webhook_sources:
|
if notification_sources:
|
||||||
print(f"Webhook 配置来源: {', '.join(webhook_sources)}")
|
print(f"通知渠道配置来源: {', '.join(notification_sources)}")
|
||||||
else:
|
else:
|
||||||
print("未配置任何 Webhook")
|
print("未配置任何通知渠道")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@ -2910,7 +2910,7 @@ def split_content_into_batches(
|
|||||||
return batches
|
return batches
|
||||||
|
|
||||||
|
|
||||||
def send_to_webhooks(
|
def send_to_notifications(
|
||||||
stats: List[Dict],
|
stats: List[Dict],
|
||||||
failed_ids: Optional[List] = None,
|
failed_ids: Optional[List] = None,
|
||||||
report_type: str = "当日汇总",
|
report_type: str = "当日汇总",
|
||||||
@ -2921,7 +2921,7 @@ def send_to_webhooks(
|
|||||||
mode: str = "daily",
|
mode: str = "daily",
|
||||||
html_file_path: Optional[str] = None,
|
html_file_path: Optional[str] = None,
|
||||||
) -> Dict[str, bool]:
|
) -> Dict[str, bool]:
|
||||||
"""发送数据到多个webhook平台"""
|
"""发送数据到多个通知平台"""
|
||||||
results = {}
|
results = {}
|
||||||
|
|
||||||
if CONFIG["SILENT_PUSH"]["ENABLED"]:
|
if CONFIG["SILENT_PUSH"]["ENABLED"]:
|
||||||
@ -2999,7 +2999,7 @@ def send_to_webhooks(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not results:
|
if not results:
|
||||||
print("未配置任何webhook URL,跳过通知发送")
|
print("未配置任何通知渠道,跳过通知发送")
|
||||||
|
|
||||||
# 如果成功发送了任何通知,且启用了每天只推一次,则记录推送
|
# 如果成功发送了任何通知,且启用了每天只推一次,则记录推送
|
||||||
if CONFIG["SILENT_PUSH"]["ENABLED"] and CONFIG["SILENT_PUSH"]["ONCE_PER_DAY"] and any(results.values()):
|
if CONFIG["SILENT_PUSH"]["ENABLED"] and CONFIG["SILENT_PUSH"]["ONCE_PER_DAY"] and any(results.values()):
|
||||||
@ -3500,14 +3500,15 @@ class NewsAnalyzer:
|
|||||||
"""获取当前模式的策略配置"""
|
"""获取当前模式的策略配置"""
|
||||||
return self.MODE_STRATEGIES.get(self.report_mode, self.MODE_STRATEGIES["daily"])
|
return self.MODE_STRATEGIES.get(self.report_mode, self.MODE_STRATEGIES["daily"])
|
||||||
|
|
||||||
def _has_webhook_configured(self) -> bool:
|
def _has_notification_configured(self) -> bool:
|
||||||
"""检查是否配置了webhook"""
|
"""检查是否配置了任何通知渠道"""
|
||||||
return any(
|
return any(
|
||||||
[
|
[
|
||||||
CONFIG["FEISHU_WEBHOOK_URL"],
|
CONFIG["FEISHU_WEBHOOK_URL"],
|
||||||
CONFIG["DINGTALK_WEBHOOK_URL"],
|
CONFIG["DINGTALK_WEBHOOK_URL"],
|
||||||
CONFIG["WEWORK_WEBHOOK_URL"],
|
CONFIG["WEWORK_WEBHOOK_URL"],
|
||||||
(CONFIG["TELEGRAM_BOT_TOKEN"] and CONFIG["TELEGRAM_CHAT_ID"]),
|
(CONFIG["TELEGRAM_BOT_TOKEN"] and CONFIG["TELEGRAM_CHAT_ID"]),
|
||||||
|
(CONFIG["EMAIL_FROM"] and CONFIG["EMAIL_PASSWORD"] and CONFIG["EMAIL_TO"]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -3635,14 +3636,14 @@ class NewsAnalyzer:
|
|||||||
html_file_path: Optional[str] = None,
|
html_file_path: Optional[str] = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""统一的通知发送逻辑,包含所有判断条件"""
|
"""统一的通知发送逻辑,包含所有判断条件"""
|
||||||
has_webhook = self._has_webhook_configured()
|
has_notification = self._has_notification_configured()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
CONFIG["ENABLE_NOTIFICATION"]
|
CONFIG["ENABLE_NOTIFICATION"]
|
||||||
and has_webhook
|
and has_notification
|
||||||
and self._has_valid_content(stats, new_titles)
|
and self._has_valid_content(stats, new_titles)
|
||||||
):
|
):
|
||||||
send_to_webhooks(
|
send_to_notifications(
|
||||||
stats,
|
stats,
|
||||||
failed_ids or [],
|
failed_ids or [],
|
||||||
report_type,
|
report_type,
|
||||||
@ -3654,13 +3655,13 @@ class NewsAnalyzer:
|
|||||||
html_file_path=html_file_path,
|
html_file_path=html_file_path,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
elif CONFIG["ENABLE_NOTIFICATION"] and not has_webhook:
|
elif CONFIG["ENABLE_NOTIFICATION"] and not has_notification:
|
||||||
print("⚠️ 警告:通知功能已启用但未配置webhook URL,将跳过通知发送")
|
print("⚠️ 警告:通知功能已启用但未配置任何通知渠道,将跳过通知发送")
|
||||||
elif not CONFIG["ENABLE_NOTIFICATION"]:
|
elif not CONFIG["ENABLE_NOTIFICATION"]:
|
||||||
print(f"跳过{report_type}通知:通知功能已禁用")
|
print(f"跳过{report_type}通知:通知功能已禁用")
|
||||||
elif (
|
elif (
|
||||||
CONFIG["ENABLE_NOTIFICATION"]
|
CONFIG["ENABLE_NOTIFICATION"]
|
||||||
and has_webhook
|
and has_notification
|
||||||
and not self._has_valid_content(stats, new_titles)
|
and not self._has_valid_content(stats, new_titles)
|
||||||
):
|
):
|
||||||
mode_strategy = self._get_mode_strategy()
|
mode_strategy = self._get_mode_strategy()
|
||||||
@ -3756,13 +3757,13 @@ class NewsAnalyzer:
|
|||||||
print("爬虫功能已禁用(ENABLE_CRAWLER=False),程序退出")
|
print("爬虫功能已禁用(ENABLE_CRAWLER=False),程序退出")
|
||||||
return
|
return
|
||||||
|
|
||||||
has_webhook = self._has_webhook_configured()
|
has_notification = self._has_notification_configured()
|
||||||
if not CONFIG["ENABLE_NOTIFICATION"]:
|
if not CONFIG["ENABLE_NOTIFICATION"]:
|
||||||
print("通知功能已禁用(ENABLE_NOTIFICATION=False),将只进行数据抓取")
|
print("通知功能已禁用(ENABLE_NOTIFICATION=False),将只进行数据抓取")
|
||||||
elif not has_webhook:
|
elif not has_notification:
|
||||||
print("未配置任何webhook URL,将只进行数据抓取,不发送通知")
|
print("未配置任何通知渠道,将只进行数据抓取,不发送通知")
|
||||||
else:
|
else:
|
||||||
print("通知功能已启用,将发送webhook通知")
|
print("通知功能已启用,将发送通知")
|
||||||
|
|
||||||
mode_strategy = self._get_mode_strategy()
|
mode_strategy = self._get_mode_strategy()
|
||||||
print(f"报告模式: {self.report_mode}")
|
print(f"报告模式: {self.report_mode}")
|
||||||
|
|||||||
23
readme.md
23
readme.md
@ -9,7 +9,7 @@
|
|||||||
[](https://github.com/sansan0/TrendRadar/stargazers)
|
[](https://github.com/sansan0/TrendRadar/stargazers)
|
||||||
[](https://github.com/sansan0/TrendRadar/network/members)
|
[](https://github.com/sansan0/TrendRadar/network/members)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://github.com/sansan0/TrendRadar)
|
[](https://github.com/sansan0/TrendRadar)
|
||||||
|
|
||||||
[](https://work.weixin.qq.com/)
|
[](https://work.weixin.qq.com/)
|
||||||
[](https://telegram.org/)
|
[](https://telegram.org/)
|
||||||
@ -23,12 +23,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
> 本项目以轻量,易部署为目标。
|
> 本项目以轻量,易部署为目标
|
||||||
>
|
>
|
||||||
> 遇到问题可选择以下 2 种方式获得帮助,[点此跳转到两者的区别](#问题答疑与1元点赞)
|
> 遇到问题可选以下 2 种方式求助【[两者区别](#问题答疑与1元点赞)】
|
||||||
|
|
||||||
- **详细问题** → 选择 【[GitHub Issues](https://github.com/sansan0/TrendRadar/issues)】,准备好截图和日志等。
|
- **详细问题** → 选择 【[GitHub Issues](https://github.com/sansan0/TrendRadar/issues)】,准备好截图和日志等
|
||||||
- **快速咨询** → 选择【[硅基茶水间](#问题答疑与1元点赞)】公众号文章留言或私信,尽量说清核心问题。
|
- **快速咨询** → 选择【[硅基茶水间](#问题答疑与1元点赞)】公众号文章留言或私信,尽量说清核心问题
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>👉 点击查看<strong>致谢名单</strong> (当前 <strong>🔥24🔥</strong> 位)</summary>
|
<summary>👉 点击查看<strong>致谢名单</strong> (当前 <strong>🔥24🔥</strong> 位)</summary>
|
||||||
@ -468,6 +468,16 @@ GitHub 一键 Fork 即可使用,无需编程基础。
|
|||||||
|
|
||||||
> 挖坑:下一次**新功能**,大概会是 ai 分析功能(●'◡'●)
|
> 挖坑:下一次**新功能**,大概会是 ai 分析功能(●'◡'●)
|
||||||
|
|
||||||
|
### 2025/09/26 - v2.3.2
|
||||||
|
|
||||||
|
- 修正了邮件通知配置检查被遗漏的问题([#88](https://github.com/sansan0/TrendRadar/issues/88))
|
||||||
|
|
||||||
|
**修复说明**:
|
||||||
|
- 解决了即使正确配置邮件通知,系统仍提示"未配置任何webhook"的问题
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><strong>👉 历史更新</strong></summary>
|
||||||
|
|
||||||
### 2025/09/22 - v2.3.1
|
### 2025/09/22 - v2.3.1
|
||||||
|
|
||||||
- **新增邮件推送功能**,支持将热点新闻报告发送到邮箱
|
- **新增邮件推送功能**,支持将热点新闻报告发送到邮箱
|
||||||
@ -484,9 +494,6 @@ GitHub 一键 Fork 即可使用,无需编程基础。
|
|||||||
**更新提示**:
|
**更新提示**:
|
||||||
- 此次更新的内容比较多,如果想升级,建议采用【大版本升级】
|
- 此次更新的内容比较多,如果想升级,建议采用【大版本升级】
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>👉 历史更新</strong></summary>
|
|
||||||
|
|
||||||
### 2025/09/17 - v2.2.0
|
### 2025/09/17 - v2.2.0
|
||||||
|
|
||||||
- 新增一键保存新闻图片功能,让你轻松分享关注的热点
|
- 新增一键保存新闻图片功能,让你轻松分享关注的热点
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user