⭐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 等渠道智能推送。
Python aibarkdata-analysisdockerhot-newsllmmailmcpmcp-servernewsntfypythonrsstrending-topicswechatwework
v2.4.2
sansana118a788fd61
diff --git a/.github/workflows/crawler.yml b/.github/workflows/crawler.ymlindex 2fe827cc58..cb0e231a40 100644--- a/.github/workflows/crawler.yml+++ b/.github/workflows/crawler.yml@@ -58,6 +58,9 @@ jobs:EMAIL_TO: ${{ secrets.EMAIL_TO }}EMAIL_SMTP_SERVER: ${{ secrets.EMAIL_SMTP_SERVER }}EMAIL_SMTP_PORT: ${{ secrets.EMAIL_SMTP_PORT }}+ NTFY_TOPIC: ${{ secrets.NTFY_TOPIC }}+ NTFY_SERVER_URL: ${{ secrets.NTFY_SERVER_URL }}+ NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }}GITHUB_ACTIONS: truerun: python main.pydiff --git a/config/config.yaml b/config/config.yamlindex 1edf013501..ac9377add2 100644--- a/config/config.yaml+++ b/config/config.yaml@@ -58,6 +58,9 @@ notification:email_to: "" # 收件人邮箱地址,多个收件人用逗号分隔email_smtp_server: "" # SMTP服务器地址(可选,留空自动识别)email_smtp_port: "" # SMTP端口(可选,留空自动识别)+ ntfy_server_url: "https://ntfy.sh" # ntfy服务器地址,默认使用公共服务,可改为自托管地址+ ntfy_topic: "" # ntfy主题名称+ ntfy_token: "" # ntfy访问令牌(可选,用于私有主题)# 用于让关注度更高的新闻在更前面显示,即用算法重新组合不同平台的热搜排序形成你侧重的热搜,合起来是 1 就行weight:diff --git a/main.py b/main.pyindex 34a493b8c1..ac54e99592 100644--- a/main.py+++ b/main.py@@ -20,7 +20,7 @@ import requestsimport yaml-VERSION = "2.4.1"+VERSION = "2.4.2"# === SMTP邮件配置 ===@@ -3738,9 +3738,9 @@ def send_to_ntfy(headers = {"Content-Type": "text/plain; charset=utf-8","Markdown": "yes",- "Title": f"TrendRadar Report - {report_type_en}",+ "Title": report_type_en,"Priority": "default",- "Tags": "newspaper,📰",+ "Tags": "news",}if token:@@ -3761,27 +3761,37 @@ def send_to_ntfy(report_data, "ntfy", update_info, max_bytes=3800, mode=mode)- print(f"ntfy消息分为 {len(batches)} 批次发送 [{report_type}]")+ total_batches = len(batches)+ print(f"ntfy消息分为 {total_batches} 批次发送 [{report_type}]")- # 逐批发送+ # 反转批次顺序,使得在ntfy客户端显示时顺序正确+ # ntfy显示最新消息在上面,所以我们从最后一批开始推送+ reversed_batches = list(reversed(batches))++ print(f"ntfy将按反向顺序推送(最后批次先推送),确保客户端显示顺序正确")++ # 逐批发送(反向顺序)success_count = 0- for i, batch_content in enumerate(batches, 1):+ for idx, batch_content in enumerate(reversed_batches, 1):+ # 计算正确的批次编号(用户视角的编号)+ actual_batch_num = total_batches - idx + 1+batch_size = len(batch_content.encode("utf-8"))print(- f"发送ntfy第 {i}/{len(batches)} 批次,大小:{batch_size} 字节 [{report_type}]"+ f"发送ntfy第 {actual_batch_num}/{total_batches} 批次(推送顺序: {idx}/{total_batches}),大小:{batch_size} 字节 [{report_type}]")# 检查消息大小,确保不超过4KBif batch_size > 4096:- print(f"警告:ntfy第 {i} 批次消息过大({batch_size} 字节),可能被拒绝")+ print(f"警告:ntfy第 {actual_batch_num} 批次消息过大({batch_size} 字节),可能被拒绝")- # 添加批次标识+ # 添加批次标识(使用正确的批次编号)current_headers = headers.copy()- if len(batches) > 1:- batch_header = f"**[第 {i}/{len(batches)} 批次]**\n\n"+ if total_batches > 1:+ batch_header = f"**[第 {actual_batch_num}/{total_batches} 批次]**\n\n"batch_content = batch_header + batch_contentcurrent_headers["Title"] = (- f"TrendRadar Report - {report_type_en} ({i}/{len(batches)})"+ f"{report_type_en} ({actual_batch_num}/{total_batches})")try:@@ -3794,15 +3804,15 @@ def send_to_ntfy()if response.status_code == 200:- print(f"ntfy第 {i}/{len(batches)} 批次发送成功 [{report_type}]")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次发送成功 [{report_type}]")success_count += 1- if i < len(batches):+ if idx < total_batches:# 公共服务器建议 2-3 秒,自托管可以更短interval = 2 if "ntfy.sh" in server_url else 1time.sleep(interval)elif response.status_code == 429:print(- f"ntfy第 {i}/{len(batches)} 批次速率限制 [{report_type}],等待后重试"+ f"ntfy第 {actual_batch_num}/{total_batches} 批次速率限制 [{report_type}],等待后重试")time.sleep(10) # 等待10秒后重试# 重试一次@@ -3814,19 +3824,19 @@ def send_to_ntfy(timeout=30,)if retry_response.status_code == 200:- print(f"ntfy第 {i}/{len(batches)} 批次重试成功 [{report_type}]")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次重试成功 [{report_type}]")success_count += 1else:print(- f"ntfy第 {i}/{len(batches)} 批次重试失败,状态码:{retry_response.status_code}"+ f"ntfy第 {actual_batch_num}/{total_batches} 批次重试失败,状态码:{retry_response.status_code}")elif response.status_code == 413:print(- f"ntfy第 {i}/{len(batches)} 批次消息过大被拒绝 [{report_type}],消息大小:{batch_size} 字节"+ f"ntfy第 {actual_batch_num}/{total_batches} 批次消息过大被拒绝 [{report_type}],消息大小:{batch_size} 字节")else:print(- f"ntfy第 {i}/{len(batches)} 批次发送失败 [{report_type}],状态码:{response.status_code}"+ f"ntfy第 {actual_batch_num}/{total_batches} 批次发送失败 [{report_type}],状态码:{response.status_code}")try:error_detail = response.text[:200] # 只显示前200字符的错误信息@@ -3835,20 +3845,20 @@ def send_to_ntfy(passexcept requests.exceptions.ConnectTimeout:- print(f"ntfy第 {i}/{len(batches)} 批次连接超时 [{report_type}]")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次连接超时 [{report_type}]")except requests.exceptions.ReadTimeout:- print(f"ntfy第 {i}/{len(batches)} 批次读取超时 [{report_type}]")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次读取超时 [{report_type}]")except requests.exceptions.ConnectionError as e:- print(f"ntfy第 {i}/{len(batches)} 批次连接错误 [{report_type}]:{e}")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次连接错误 [{report_type}]:{e}")except Exception as e:- print(f"ntfy第 {i}/{len(batches)} 批次发送异常 [{report_type}]:{e}")+ print(f"ntfy第 {actual_batch_num}/{total_batches} 批次发送异常 [{report_type}]:{e}")# 判断整体发送是否成功- if success_count == len(batches):- print(f"ntfy所有 {len(batches)} 批次发送完成 [{report_type}]")+ if success_count == total_batches:+ print(f"ntfy所有 {total_batches} 批次发送完成 [{report_type}]")return Trueelif success_count > 0:- print(f"ntfy部分发送成功:{success_count}/{len(batches)} 批次 [{report_type}]")+ print(f"ntfy部分发送成功:{success_count}/{total_batches} 批次 [{report_type}]")return True # 部分成功也视为成功else:print(f"ntfy发送完全失败 [{report_type}]")diff --git a/readme.md b/readme.mdindex 478adefd59..d49fa3c416 100644--- a/readme.md+++ b/readme.md@@ -11,7 +11,7 @@[](https://github.com/sansan0/TrendRadar/stargazers)[](https://github.com/sansan0/TrendRadar/network/members)[](LICENSE)-[](https://github.com/sansan0/TrendRadar)+[](https://github.com/sansan0/TrendRadar)[](https://work.weixin.qq.com/)[](https://telegram.org/)@@ -464,11 +464,16 @@ GitHub 一键 Fork 即可使用,无需编程基础。- **小版本更新**:从 v2.x 升级到 v2.y, 用本项目的 `main.py` 代码替换你 fork 仓库中的对应文件- **大版本升级**:从 v1.x 升级到 v2.y, 建议删除现有 fork 后重新 fork,这样更省力且避免配置冲突-### 2025/10/8 - v2.4.1+### 2025/10/8 - v2.4.2- 修复 ntfy 推送编码问题+- 修复配置文件缺失问题+- 优化 ntfy 推送效果- 增加 github page 图片分段导出功能+- **更新提示**:+ - 建议使用【大版本更新】+<details><summary><strong>👉 历史更新</strong></summary>diff --git a/version b/versionindex 58073ef8d7..acdc3f1b0b 100644--- a/version+++ b/version@@ -1 +1 @@-2.4.1\ No newline at end of file+2.4.2\ No newline at end of file