From a3d0032604ac47d4d3ca18518ffa8e92100cc861 Mon Sep 17 00:00:00 2001 From: sansan <77180927+sansan0@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:22:58 +0800 Subject: [PATCH] =?UTF-8?q?v3.1.0=20=E5=A2=9E=E5=8A=A0=E3=80=90=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E5=BE=AE=E4=BF=A1=E3=80=91=E6=8E=A8=E9=80=81=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/crawler.yml | 1 + README-EN.md | 126 +++++++++++----- README.md | 258 +++++++++++++++++++------------- config/config.yaml | 20 ++- docker/.env | 1 + docker/docker-compose-build.yml | 1 + docker/docker-compose.yml | 1 + main.py | 87 +++++++++-- version | 2 +- 9 files changed, 339 insertions(+), 158 deletions(-) diff --git a/.github/workflows/crawler.yml b/.github/workflows/crawler.yml index bec1508..e7d4450 100644 --- a/.github/workflows/crawler.yml +++ b/.github/workflows/crawler.yml @@ -53,6 +53,7 @@ jobs: TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} DINGTALK_WEBHOOK_URL: ${{ secrets.DINGTALK_WEBHOOK_URL }} WEWORK_WEBHOOK_URL: ${{ secrets.WEWORK_WEBHOOK_URL }} + WEWORK_MSG_TYPE: ${{ secrets.WEWORK_MSG_TYPE }} EMAIL_FROM: ${{ secrets.EMAIL_FROM }} EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }} EMAIL_TO: ${{ secrets.EMAIL_TO }} diff --git a/README-EN.md b/README-EN.md index ccf3e98..19e9ff2 100644 --- a/README-EN.md +++ b/README-EN.md @@ -13,10 +13,11 @@ [![GitHub Stars](https://img.shields.io/github/stars/sansan0/TrendRadar?style=flat-square&logo=github&color=yellow)](https://github.com/sansan0/TrendRadar/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/sansan0/TrendRadar?style=flat-square&logo=github&color=blue)](https://github.com/sansan0/TrendRadar/network/members) [![License](https://img.shields.io/badge/license-GPL--3.0-blue.svg?style=flat-square)](LICENSE) -[![Version](https://img.shields.io/badge/version-v3.0.5-blue.svg)](https://github.com/sansan0/TrendRadar) +[![Version](https://img.shields.io/badge/version-v3.1.0-blue.svg)](https://github.com/sansan0/TrendRadar) [![MCP](https://img.shields.io/badge/MCP-v1.0.2-green.svg)](https://github.com/sansan0/TrendRadar) [![WeWork](https://img.shields.io/badge/WeWork-Notification-00D4AA?style=flat-square)](https://work.weixin.qq.com/) +[![WeChat](https://img.shields.io/badge/WeChat-Notification-00D4AA?style=flat-square)](https://weixin.qq.com/) [![Telegram](https://img.shields.io/badge/Telegram-Notification-00D4AA?style=flat-square)](https://telegram.org/) [![DingTalk](https://img.shields.io/badge/DingTalk-Notification-00D4AA?style=flat-square)](#) [![Feishu](https://img.shields.io/badge/Feishu-Notification-00D4AA?style=flat-square)](https://www.feishu.cn/) @@ -250,11 +251,18 @@ Transform from "algorithm recommendation captivity" to "actively getting the inf - **Major Version Upgrade**: Upgrading from v1.x to v2.y, recommend deleting existing fork and re-forking to save effort and avoid config conflicts -### 2025/11/12 - v3.0.5 +### 2025/11/20 - v3.1.0 -- Fixed email sending SSL/TLS port configuration logic error -- Optimized email service providers (QQ/163/126) to default use port 465 (SSL) -- **Added Docker environment variable support**: Core config items (`enable_crawler`, `report_mode`, `push_window`, etc.) support override via environment variables, solving config file modification issues for NAS users (see [🐳 Docker Deployment](#-docker-deployment) chapter) +- **Added Personal WeChat Push Support**: WeWork application can push to personal WeChat without installing WeWork APP +- Supports two message formats: `markdown` (WeWork group bot) and `text` (personal WeChat app) +- Added `WEWORK_MSG_TYPE` environment variable configuration, supporting GitHub Actions, Docker, docker-compose and other deployment methods +- `text` mode automatically strips Markdown syntax for clean plain text push +- See "Personal WeChat Push" configuration in Quick Start + +**Upgrade Instructions** (GitHub Fork Users): +- Required updates: `main.py`, `config/config.yaml` +- Optional update: `.github/workflows/crawler.yml` (if using GitHub Actions) +- Recommended: Use minor version upgrade method - copy and replace the files above @@ -267,6 +275,13 @@ Transform from "algorithm recommendation captivity" to "actively getting the inf
👉 Click to expand: Historical Updates +### 2025/11/12 - v3.0.5 + +- Fixed email sending SSL/TLS port configuration logic error +- Optimized email service providers (QQ/163/126) to default use port 465 (SSL) +- **Added Docker environment variable support**: Core config items (`enable_crawler`, `report_mode`, `push_window`, etc.) support override via environment variables, solving config file modification issues for NAS users (see [🐳 Docker Deployment](#-docker-deployment) chapter) + + ### 2025/10/26 - mcp-v1.0.1 **MCP Module Update:** @@ -595,6 +610,37 @@ frequency_words.txt file added **required word** feature, using + sign #### PC Setup Process Similar
+
+ 👉 Click to expand: Personal WeChat Push (Based on WeWork app, push to personal WeChat) +
+ + > This solution is based on WeWork's plugin mechanism. The push style is plain text (no markdown format), but it can push directly to personal WeChat without installing WeWork App. + + **GitHub Secret Configuration (⚠️ Name must match exactly):** + - **Name**: `WEWORK_WEBHOOK_URL` (Please copy and paste this name, do not type manually) + - **Secret (Value)**: Your WeWork app Webhook address + + - **Name**: `WEWORK_MSG_TYPE` (Please copy and paste this name, do not type manually) + - **Secret (Value)**: `text` + +
+ + **Setup Steps:** + + 1. Complete the WeWork bot Webhook setup above + 2. Add `WEWORK_MSG_TYPE` Secret with value `text` + 3. Follow the image below to link personal WeChat + 4. After configuration, WeWork App can be deleted from phone + + + + **Notes**: + - Uses the same Webhook address as WeWork bot + - Difference is message format: `text` for plain text, `markdown` for rich text (default) + - Plain text format will automatically remove all markdown syntax (bold, links, etc.) + +
+
👉 Click to expand: Feishu Bot (Most user-friendly message display)
@@ -987,6 +1033,31 @@ frequency_words.txt file added **required word** feature, using + sign **Note**: Suggest only adjusting explicitly documented config items, other options mainly for author's development testing +5. **🎉 Deployment Success! Share Your Experience** + + Congratulations on completing TrendRadar configuration! You can now start tracking trending news. + + 💬 **Join our community to share your experience~** + + - Want to learn more tips and advanced techniques? + - Need quick help with issues? + - Have great ideas to share? + + 👉 **Follow our WeChat Official Account「硅基茶水间」(Silicon Tea Room)**, your likes and comments are the driving force for continuous updates! + + For detailed communication methods, please check → [FAQ & Support](#-faq--support) + +6. **🤖 Want Smarter Analysis? Try AI-Enhanced Features** (Optional) + + Basic configuration already meets daily needs, but if you want: + + - 📊 Let AI automatically analyze trending topics and data insights + - 🔍 Search and query news using natural language + - 💡 Get sentiment analysis, topic prediction, and deep analytics + - ⚡ Directly access data in AI tools like Claude, Cursor, etc. + + 👉 **Learn More**: [AI Analysis](#-ai-analysis) — Unlock hidden capabilities and make trend tracking more efficient! + ## ⚙️ Configuration Guide @@ -1853,37 +1924,27 @@ Any client supporting Model Context Protocol can connect to TrendRadar: ## ☕ FAQ & Support -> If you want to support this project, you can search **Tencent Charity** on WeChat and donate to **Education Support Programs** as you wish~ +> If you want to support this project, you can search **Tencent Charity** on WeChat and donate to **Education Support Programs** as you wish > -> We're anxious about information overload, while they struggle in information deserts without even learning opportunities, so they need support more than me. - -
-👉 Click to expand: Author's Note -
- -Thanks for all support! Due to 302.AI sponsorship, my personal **one-yuan donation** QR code has been removed. - -Previous **one-yuan supporters** are listed in the **Acknowledgments** section at the top. - -This project's development and maintenance require significant time, effort, and costs (including AI model fees). With sponsorship support, I can maintain it more confidently. - -Currently, major AI model prices are relatively affordable. Welcome to register and try, you can **[click here to claim $1 free credit](#-sponsors)**. - -
+> Thanks to those who participated in the **one-yuan donation**! You are listed in the **Acknowledgments** at the top. Your support gives more motivation to open source maintenance. Personal donation QR code has been removed. - **GitHub Issues**: Suitable for targeted answers. Please provide complete info when asking (screenshots, error logs, system environment, etc.) - **WeChat Official Account**: Suitable for quick consultation. Suggest priority to communicate in public comment area of related articles. If private message, please use polite language 😉 -- 💡 Deployment successful? Welcome to leave comments and likes on our official account to share your experience~ +- 💡 Deployment successful? Come to our official account to share your experience! Your likes and suggestions are the driving force for continuous updates~
| WeChat Official Account | |:---:| -| | +| |
+
+ +--- + ## 🪄 Sponsors > **302.AI** is a pay-as-you-go enterprise-level AI resource platform @@ -2021,7 +2082,7 @@ A: You can top up as needed, pay-as-you-go. Major AI model prices are now relati ### Project Articles -> **Related Articles** (Chinese): +> **4 Related Articles** (Chinese): - [Comment here for mobile Q&A by project author](https://mp.weixin.qq.com/s/KYEPfTPVzZNWFclZh4am_g) - [Breaking 1000 stars in 2 months - My GitHub project promotion experience](https://mp.weixin.qq.com/s/jzn0vLiQFX408opcfpPPxQ) @@ -2034,7 +2095,7 @@ A: You can top up as needed, pay-as-you-go. Major AI model prices are now relati - **Core Function**: Quickly filter project code to feed AI, you just need to add personal requirements - **Project Address**: https://github.com/sansan0/ai-code-context-helper -## ⭐ Related Projects +### Other Projects > 📍 Chairman Mao's Footprint Map - Interactive dynamic display of complete trajectory 1893-1976. Welcome comrades to contribute data @@ -2045,21 +2106,6 @@ A: You can top up as needed, pay-as-you-go. Major AI model prices are now relati - https://github.com/sansan0/bilibili-comment-analyzer -
-👉 Click to expand: WeChat Push Notification Solution -
- -> Since this solution is based on WeWork's plugin mechanism and has very different push styles, I temporarily don't plan to include related implementation in the current project - -- Fork this user's project: https://github.com/jayzqj/TrendRadar -- Complete WeWork push setup above -- Follow the image below to operate -- After configuration, you can delete WeWork app from your phone - - - -
- ### Project Workflow Diagram ```mermaid diff --git a/README.md b/README.md index d9e91af..e886585 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,11 @@ [![GitHub Stars](https://img.shields.io/github/stars/sansan0/TrendRadar?style=flat-square&logo=github&color=yellow)](https://github.com/sansan0/TrendRadar/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/sansan0/TrendRadar?style=flat-square&logo=github&color=blue)](https://github.com/sansan0/TrendRadar/network/members) [![License](https://img.shields.io/badge/license-GPL--3.0-blue.svg?style=flat-square)](LICENSE) -[![Version](https://img.shields.io/badge/version-v3.0.5-blue.svg)](https://github.com/sansan0/TrendRadar) +[![Version](https://img.shields.io/badge/version-v3.1.0-blue.svg)](https://github.com/sansan0/TrendRadar) [![MCP](https://img.shields.io/badge/MCP-v1.0.2-green.svg)](https://github.com/sansan0/TrendRadar) [![企业微信通知](https://img.shields.io/badge/企业微信-通知-00D4AA?style=flat-square)](https://work.weixin.qq.com/) +[![个人微信通知](https://img.shields.io/badge/个人微信-通知-00D4AA?style=flat-square)](https://weixin.qq.com/) [![Telegram通知](https://img.shields.io/badge/Telegram-通知-00D4AA?style=flat-square)](https://telegram.org/) [![dingtalk通知](https://img.shields.io/badge/钉钉-通知-00D4AA?style=flat-square)](#) [![飞书通知](https://img.shields.io/badge/飞书-通知-00D4AA?style=flat-square)](https://www.feishu.cn/) @@ -314,11 +315,18 @@ GitHub 一键 Fork 即可使用,无需编程基础。 - **大版本升级**:从 v1.x 升级到 v2.y,建议删除现有 fork 后重新 fork,这样更省力且避免配置冲突 -### 2025/11/12 - v3.0.5 +### 2025/11/20 - v3.1.0 -- 修复邮件发送 SSL/TLS 端口配置逻辑错误 -- 优化邮箱服务商(QQ/163/126)默认使用 465 端口(SSL) -- **新增 Docker 环境变量支持**:核心配置项(`enable_crawler`、`report_mode`、`push_window` 等)支持通过环境变量覆盖,解决 NAS 用户修改配置文件不生效的问题(详见 [🐳 Docker 部署](#-docker-部署) 章节) +- **新增个人微信推送支持**:企业微信应用可推送到个人微信,无需安装企业微信 APP +- 支持两种消息格式:`markdown`(企业微信群机器人)和 `text`(个人微信应用) +- 新增 `WEWORK_MSG_TYPE` 环境变量配置,支持 GitHub Actions、Docker、docker-compose 等多种部署方式 +- `text` 模式自动清除 Markdown 语法,提供纯文本推送效果 +- 详见快速开始中的「个人微信推送」配置说明 + +**升级说明**(GitHub Fork 用户): +- 必须更新:`main.py`、`config/config.yaml` +- 可选更新:`.github/workflows/crawler.yml`(如使用 GitHub Actions 部署) +- 建议使用小版本升级方式:复制替换上述文件 @@ -331,6 +339,13 @@ GitHub 一键 Fork 即可使用,无需编程基础。
👉 点击展开:历史更新 +### 2025/11/12 - v3.0.5 + +- 修复邮件发送 SSL/TLS 端口配置逻辑错误 +- 优化邮箱服务商(QQ/163/126)默认使用 465 端口(SSL) +- **新增 Docker 环境变量支持**:核心配置项(`enable_crawler`、`report_mode`、`push_window` 等)支持通过环境变量覆盖,解决 NAS 用户修改配置文件不生效的问题(详见 [🐳 Docker 部署](#-docker-部署) 章节) + + ### 2025/10/26 - mcp-v1.0.1 **MCP 模块更新:** @@ -651,6 +666,37 @@ frequency_words.txt 文件增加了一个【必须词】功能,使用 + 号 #### PC 端设置流程类似
+
+ 👉 点击展开:个人微信推送(基于企业微信应用,推送到个人微信) +
+ + > 由于该方案是基于企业微信的插件机制,推送样式为纯文本(无 markdown 格式),但可以直接推送到个人微信,无需安装企业微信 App。 + + **GitHub Secret 配置(⚠️ Name 名称必须严格一致):** + - **Name(名称)**:`WEWORK_WEBHOOK_URL`(请复制粘贴此名称,不要手打) + - **Secret(值)**:你的企业微信应用 Webhook 地址 + + - **Name(名称)**:`WEWORK_MSG_TYPE`(请复制粘贴此名称,不要手打) + - **Secret(值)**:`text` + +
+ + **设置步骤:** + + 1. 完成上方的企业微信机器人 Webhook 设置 + 2. 添加 `WEWORK_MSG_TYPE` Secret,值设为 `text` + 3. 按照下面图片操作,关联个人微信 + 4. 配置好后,手机上的企业微信 App 可以删除 + + + + **说明**: + - 与企业微信机器人使用相同的 Webhook 地址 + - 区别在于消息格式:`text` 为纯文本,`markdown` 为富文本(默认) + - 纯文本格式会自动去除所有 markdown 语法(粗体、链接等) + +
+
👉 点击展开:飞书机器人(消息显示最友好)
@@ -1038,7 +1084,32 @@ frequency_words.txt 文件增加了一个【必须词】功能,使用 + 号 - **关键词设置**:在 [config/frequency_words.txt](config/frequency_words.txt) 中添加你关心的关键词 - **推送频率调整**:在 [.github/workflows/crawler.yml](.github/workflows/crawler.yml) 请谨慎调整,别贪心 - **注意**:建议只调整文档中明确说明的配置项,其他选项主要供作者开发时测试使用 + **注意**:建议只调整文档中明确说明的配置项,其他选项主要供作者开发时测试使用 + +5. **🎉 部署成功!分享你的使用体验** + + 恭喜你完成了 TrendRadar 的配置!现在你可以开始追踪热点资讯了。 + + 💬 **有更多小伙伴在公众号交流使用心得,期待你的分享~** + + - 想了解更多玩法和高级技巧? + - 遇到问题需要快速解答? + - 有好的想法想要交流? + + 👉 **欢迎关注公众号「硅基茶水间」**,你的点赞和留言都是项目持续更新的动力。 + + 详细的交流方式,请查看 → [问题答疑与交流](#问题答疑与交流) + +6. **想要更智能的分析?试试 AI 增强功能**(可选) + + 基础配置已经能满足日常使用,但如果你想要: + + - 📊 让 AI 自动分析热点趋势和数据洞察 + - 🔍 通过自然语言搜索和查询新闻 + - 💡 获得情感分析、话题预测等深度分析 + - ⚡ 在 Claude、Cursor 等 AI 工具中直接调用数据 + + 👉 **了解更多**:[AI 智能分析](#-ai-智能分析) — 解锁项目的隐藏能力,让热点追踪更高效! ## ⚙️ 配置详解 @@ -1904,89 +1975,6 @@ MCP Inspector 是官方调试工具,用于测试 MCP 连接:
-## ☕问题答疑与交流 - -> 如果你想支持本项目,可通过微信搜索**腾讯公益**,对里面的**助学计划**随心捐助~ -> -> 我还在为信息过载而焦虑,而他们却在信息荒漠中挣扎,他们比我更需要支持。 - -
-👉 点击展开:作者有话说 -
- -感谢各位支持!因获得[赞助商](#-赞助商)的赞助,现已移除我个人的**一元点赞**打赏码。 - -之前参与**一元点赞**的朋友已收录至顶部**致谢名单**。 - -本项目开发和维护投入了大量时间、精力和成本(含 AI 模型费用),有了赞助支持后可以更安心维护。 -
- -- **GitHub Issues**:适合针对性强的解答。提问时请提供完整信息(截图、错误日志、系统环境等)。 -- **公众号交流**:适合快速咨询。建议优先在相关文章下的公共留言区交流,如私信,请文明礼貌用语😉 -- 💡 部署成功了?欢迎来公众号留言点赞,分享你的使用体验~ - - -
- -|公众号关注 | -|:---:| -| | - -
- -## 🪄 赞助商 - -> **302.AI** 是按用量付费的企业级 AI 资源平台 -> 提供市场上最新、最全面的 **AI 模型**和 **API**,以及多种开箱即用的在线 AI 应用 - -
- - - 302.AI - -
- -### 💰 302.AI 新用户福利 - -> 领取的 1 美元可用于调用各种 AI 大模型(如 Claude、GPT 等) -> 本项目 AI 分析功能需配置大模型使用,配置教程详见 [AI 智能分析](#-ai-智能分析) - -[![注册领取](https://img.shields.io/badge/注册_302.AI-领取_1_美元免费测试额度-FF6B6B?style=for-the-badge&logo=openai&logoColor=white)](https://share.302.ai/mEOUzG) - - - -
- ---- - ### 常见问题 @@ -2068,6 +2056,83 @@ A: 可以按需充值,按量付费。目前大厂模型价格已相对亲民
+ +## ☕问题答疑与交流 + +> 如果你想支持本项目,可通过微信搜索**腾讯公益**,对里面的**助学**相关的项目随心捐助 +> +> 感谢参与过**一元点赞**的朋友,已收录至顶部**致谢名单**!你们的支持让开源维护更有动力,个人打赏码现已移除。 + +- **GitHub Issues**:适合针对性强的解答。提问时请提供完整信息(截图、错误日志、系统环境等)。 +- **公众号交流**:适合快速咨询。建议优先在相关文章下的公共留言区交流,如私信,请文明礼貌用语😉 +- 💡 部署成功了?来公众号说说感受吧,你的点赞和留言都是我继续更新的动力~ + + +
+ +|公众号关注 | +|:---:| +| | + +
+ +
+ +--- + +## 🪄 赞助商 + +> **302.AI** 是按用量付费的企业级 AI 资源平台 +> 提供市场上最新、最全面的 **AI 模型**和 **API**,以及多种开箱即用的在线 AI 应用 + +
+ + + 302.AI + +
+ +### 💰 302.AI 新用户福利 + +> 领取的 1 美元可用于调用各种 AI 大模型(如 Claude、GPT 等) +> 本项目 AI 分析功能需配置大模型使用,配置教程详见 [AI 智能分析](#-ai-智能分析) + +[![注册领取](https://img.shields.io/badge/注册_302.AI-领取_1_美元免费测试额度-FF6B6B?style=for-the-badge&logo=openai&logoColor=white)](https://share.302.ai/mEOUzG) + + + +--- + +
+ ### 项目相关 > **4 篇文章**: @@ -2094,21 +2159,6 @@ A: 可以按需充值,按量付费。目前大厂模型价格已相对亲民 - https://github.com/sansan0/bilibili-comment-analyzer -
-👉 点击展开:微信推送通知方案 -
- -> 由于该方案是基于企业微信的插件机制,推送样式也十分不同,所以相关实现我暂时不准备纳入当前项目 - -- fork 这位兄台的项目 https://github.com/jayzqj/TrendRadar -- 完成上方的企业微信推送设置 -- 按照下面图片操作 -- 配置好后,手机上的企业微信 app 删除掉也没事 - - - -
- ### 本项目流程图 ```mermaid diff --git a/config/config.yaml b/config/config.yaml index 6cda1a2..0c2622a 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -51,13 +51,27 @@ notification: once_per_day: true # 每天在时间窗口内只推送一次,如果 false,则窗口内每次执行都推送 push_record_retention_days: 7 # 推送记录保留天数 - # 请务必妥善保管好 webhooks,不要公开 - # 如果你以 fork 的方式将本项目部署在 GitHub 上,请勿在此填写任何 webhooks,而是将 webhooks 填入 GitHub Secret - # 不然轻则手机上收到奇怪的广告推送,重则存在更严重的安全隐患 + # ⚠️⚠️⚠️ 重要安全警告 / IMPORTANT SECURITY WARNING ⚠️⚠️⚠️ + # + # 🔴 请务必妥善保管好 webhooks,不要公开!!! + # 🔴 如果你以 fork 的方式将本项目部署在 GitHub 上,请勿在下面填写任何 webhooks + # 🔴 而是将 webhooks 填入 GitHub Secret(Settings → Secrets and variables → Actions) + # 🔴 否则: + # - 轻则:手机上收到大量垃圾广告推送 + # - 重则:webhook 被滥用造成严重安全隐患(如恶意消息轰炸、钓鱼链接等) + # + # 🔴 NEVER expose webhooks publicly!!! + # 🔴 If deploying via GitHub fork, DO NOT fill webhooks below + # 🔴 Instead, add them to GitHub Secrets (Settings → Secrets and variables → Actions) + # 🔴 Consequences of exposure: + # - Minor: Spam notifications flooding your devices + # - Severe: Webhook abuse leading to security incidents (malicious messages, phishing links, etc.) + # webhooks: feishu_url: "" # 飞书机器人的 webhook URL dingtalk_url: "" # 钉钉机器人的 webhook URL wework_url: "" # 企业微信机器人的 webhook URL + wework_msg_type: "markdown" # 企业微信消息类型:markdown(群机器人) 或 text(个人微信应用) telegram_bot_token: "" # Telegram Bot Token telegram_chat_id: "" # Telegram Chat ID email_from: "" # 发件人邮箱地址 diff --git a/docker/.env b/docker/.env index c20194a..41d6acc 100644 --- a/docker/.env +++ b/docker/.env @@ -34,6 +34,7 @@ TELEGRAM_BOT_TOKEN= TELEGRAM_CHAT_ID= DINGTALK_WEBHOOK_URL= WEWORK_WEBHOOK_URL= +WEWORK_MSG_TYPE= EMAIL_FROM= EMAIL_PASSWORD= diff --git a/docker/docker-compose-build.yml b/docker/docker-compose-build.yml index 5dc69d8..8d7ccb3 100644 --- a/docker/docker-compose-build.yml +++ b/docker/docker-compose-build.yml @@ -28,6 +28,7 @@ services: - TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID:-} - DINGTALK_WEBHOOK_URL=${DINGTALK_WEBHOOK_URL:-} - WEWORK_WEBHOOK_URL=${WEWORK_WEBHOOK_URL:-} + - WEWORK_MSG_TYPE=${WEWORK_MSG_TYPE:-} # 邮件配置 - EMAIL_FROM=${EMAIL_FROM:-} - EMAIL_PASSWORD=${EMAIL_PASSWORD:-} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 94f47fb..be920f5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -26,6 +26,7 @@ services: - TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID:-} - DINGTALK_WEBHOOK_URL=${DINGTALK_WEBHOOK_URL:-} - WEWORK_WEBHOOK_URL=${WEWORK_WEBHOOK_URL:-} + - WEWORK_MSG_TYPE=${WEWORK_MSG_TYPE:-} # 邮件配置 - EMAIL_FROM=${EMAIL_FROM:-} - EMAIL_PASSWORD=${EMAIL_PASSWORD:-} diff --git a/main.py b/main.py index 7880b5a..fbf292f 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ import requests import yaml -VERSION = "3.0.5" +VERSION = "3.1.0" # === SMTP邮件配置 === @@ -144,6 +144,9 @@ def load_config(): config["WEWORK_WEBHOOK_URL"] = os.environ.get( "WEWORK_WEBHOOK_URL", "" ).strip() or webhooks.get("wework_url", "") + config["WEWORK_MSG_TYPE"] = os.environ.get( + "WEWORK_MSG_TYPE", "" + ).strip() or webhooks.get("wework_msg_type", "markdown") config["TELEGRAM_BOT_TOKEN"] = os.environ.get( "TELEGRAM_BOT_TOKEN", "" ).strip() or webhooks.get("telegram_bot_token", "") @@ -3583,6 +3586,50 @@ def send_to_dingtalk( return True +def strip_markdown(text: str) -> str: + """去除文本中的 markdown 语法格式,用于个人微信推送""" + + # 去除粗体 **text** 或 __text__ + text = re.sub(r'\*\*(.+?)\*\*', r'\1', text) + text = re.sub(r'__(.+?)__', r'\1', text) + + # 去除斜体 *text* 或 _text_ + text = re.sub(r'\*(.+?)\*', r'\1', text) + text = re.sub(r'_(.+?)_', r'\1', text) + + # 去除删除线 ~~text~~ + text = re.sub(r'~~(.+?)~~', r'\1', text) + + # 转换链接 [text](url) -> text url(保留 URL) + text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'\1 \2', text) + # 如果不需要保留 URL,可以使用下面这行(只保留标题文本): + # text = re.sub(r'\[([^\]]+)\]\([^)]+\)', r'\1', text) + + # 去除图片 ![alt](url) -> alt + text = re.sub(r'!\[(.+?)\]\(.+?\)', r'\1', text) + + # 去除行内代码 `code` + text = re.sub(r'`(.+?)`', r'\1', text) + + # 去除引用符号 > + text = re.sub(r'^>\s*', '', text, flags=re.MULTILINE) + + # 去除标题符号 # ## ### 等 + text = re.sub(r'^#+\s*', '', text, flags=re.MULTILINE) + + # 去除水平分割线 --- 或 *** + text = re.sub(r'^[\-\*]{3,}\s*$', '', text, flags=re.MULTILINE) + + # 去除 HTML 标签 text -> text + text = re.sub(r']*>(.+?)', r'\1', text) + text = re.sub(r'<[^>]+>', '', text) + + # 清理多余的空行(保留最多两个连续空行) + text = re.sub(r'\n{3,}', '\n\n', text) + + return text.strip() + + def send_to_wework( webhook_url: str, report_data: Dict, @@ -3591,12 +3638,21 @@ def send_to_wework( proxy_url: Optional[str] = None, mode: str = "daily", ) -> bool: - """发送到企业微信(支持分批发送)""" + """发送到企业微信(支持分批发送,支持 markdown 和 text 两种格式)""" headers = {"Content-Type": "application/json"} proxies = None if proxy_url: proxies = {"http": proxy_url, "https": proxy_url} + # 获取消息类型配置(markdown 或 text) + msg_type = CONFIG.get("WEWORK_MSG_TYPE", "markdown").lower() + is_text_mode = msg_type == "text" + + if is_text_mode: + print(f"企业微信使用 text 格式(个人微信模式)[{report_type}]") + else: + print(f"企业微信使用 markdown 格式(群机器人模式)[{report_type}]") + # 获取分批内容 batches = split_content_into_batches(report_data, "wework", update_info, mode=mode) @@ -3604,18 +3660,29 @@ def send_to_wework( # 逐批发送 for i, batch_content in enumerate(batches, 1): - batch_size = len(batch_content.encode("utf-8")) + # 添加批次标识 + if len(batches) > 1: + if is_text_mode: + batch_header = f"[第 {i}/{len(batches)} 批次]\n\n" + else: + batch_header = f"**[第 {i}/{len(batches)} 批次]**\n\n" + batch_content = batch_header + batch_content + + # 根据消息类型构建 payload + if is_text_mode: + # text 格式:去除 markdown 语法 + plain_content = strip_markdown(batch_content) + payload = {"msgtype": "text", "text": {"content": plain_content}} + batch_size = len(plain_content.encode("utf-8")) + else: + # markdown 格式:保持原样 + payload = {"msgtype": "markdown", "markdown": {"content": batch_content}} + batch_size = len(batch_content.encode("utf-8")) + print( f"发送企业微信第 {i}/{len(batches)} 批次,大小:{batch_size} 字节 [{report_type}]" ) - # 添加批次标识 - if len(batches) > 1: - batch_header = f"**[第 {i}/{len(batches)} 批次]**\n\n" - batch_content = batch_header + batch_content - - payload = {"msgtype": "markdown", "markdown": {"content": batch_content}} - try: response = requests.post( webhook_url, headers=headers, json=payload, proxies=proxies, timeout=30 diff --git a/version b/version index 7da3c16..a0cd9f0 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.5 \ No newline at end of file +3.1.0 \ No newline at end of file