diff --git a/config/config.yaml b/config/config.yaml index a9c3cd0..8cfec30 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -35,14 +35,19 @@ notification: batch_send_interval: 1 # 批次发送间隔(秒) feishu_message_separator: "━━━━━━━━━━━━━━━━━━━" # feishu 消息分割线 - silent_push: - enabled: false # 是否启用静默推送模式,如果 true,则启用 - # 因为我们白嫖的 github 服务器执行时间不稳定,所以时间范围要尽可能大一点,至少留足 2 小时 - # 如果你想寻求稳定的按时的推送,建议通过 docker 部署在个人的服务器上 + # 🕐 推送时间窗口控制(可选功能) + # 用途:限制推送的时间范围,避免非工作时间打扰 + # 适用场景: + # - 只想在工作日白天接收推送(如 9:00-18:00) + # - 希望在晚上固定时间收到汇总(如 20:00-22:00) + push_window: + enabled: false # 是否启用推送时间窗口控制,默认关闭 + # 注意:GitHub Actions 执行时间不稳定,时间范围建议至少留足 2 小时 + # 如果想要精准的定时推送,建议使用 Docker 部署在个人服务器上 time_range: - start: "20:00" # 推送时间范围开始(北京时间) - end: "22:00" # 推送时间范围结束(北京时间) - once_per_day: true # 每天在时间范围内只推送一次,如果 false,则时间范围内每次执行都推送一次 + start: "20:00" # 推送时间窗口开始(北京时间) + end: "22:00" # 推送时间窗口结束(北京时间) + once_per_day: true # 每天在时间窗口内只推送一次,如果 false,则窗口内每次执行都推送 push_record_retention_days: 7 # 推送记录保留天数 # 请务必妥善保管好 webhooks,不要公开 diff --git a/main.py b/main.py index ac54e99..abcec14 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ import requests import yaml -VERSION = "2.4.2" +VERSION = "2.4.3" # === SMTP邮件配置 === @@ -83,25 +83,25 @@ def load_config(): "FEISHU_MESSAGE_SEPARATOR": config_data["notification"][ "feishu_message_separator" ], - "SILENT_PUSH": { + "PUSH_WINDOW": { "ENABLED": config_data["notification"] - .get("silent_push", {}) + .get("push_window", {}) .get("enabled", False), "TIME_RANGE": { "START": config_data["notification"] - .get("silent_push", {}) + .get("push_window", {}) .get("time_range", {}) .get("start", "08:00"), "END": config_data["notification"] - .get("silent_push", {}) + .get("push_window", {}) .get("time_range", {}) .get("end", "22:00"), }, "ONCE_PER_DAY": config_data["notification"] - .get("silent_push", {}) + .get("push_window", {}) .get("once_per_day", True), "RECORD_RETENTION_DAYS": config_data["notification"] - .get("silent_push", {}) + .get("push_window", {}) .get("push_record_retention_days", 7), }, "WEIGHT_CONFIG": { @@ -328,7 +328,7 @@ class PushRecordManager: def cleanup_old_records(self): """清理过期的推送记录""" - retention_days = CONFIG["SILENT_PUSH"]["RECORD_RETENTION_DAYS"] + retention_days = CONFIG["PUSH_WINDOW"]["RECORD_RETENTION_DAYS"] current_time = get_beijing_time() for record_file in self.record_dir.glob("push_record_*.json"): @@ -3215,24 +3215,24 @@ def send_to_notifications( """发送数据到多个通知平台""" results = {} - if CONFIG["SILENT_PUSH"]["ENABLED"]: + if CONFIG["PUSH_WINDOW"]["ENABLED"]: push_manager = PushRecordManager() - time_range_start = CONFIG["SILENT_PUSH"]["TIME_RANGE"]["START"] - time_range_end = CONFIG["SILENT_PUSH"]["TIME_RANGE"]["END"] + time_range_start = CONFIG["PUSH_WINDOW"]["TIME_RANGE"]["START"] + time_range_end = CONFIG["PUSH_WINDOW"]["TIME_RANGE"]["END"] if not push_manager.is_in_time_range(time_range_start, time_range_end): now = get_beijing_time() print( - f"静默模式:当前时间 {now.strftime('%H:%M')} 不在推送时间范围 {time_range_start}-{time_range_end} 内,跳过推送" + f"推送窗口控制:当前时间 {now.strftime('%H:%M')} 不在推送时间窗口 {time_range_start}-{time_range_end} 内,跳过推送" ) return results - if CONFIG["SILENT_PUSH"]["ONCE_PER_DAY"]: + if CONFIG["PUSH_WINDOW"]["ONCE_PER_DAY"]: if push_manager.has_pushed_today(): - print(f"静默模式:今天已推送过,跳过本次推送") + print(f"推送窗口控制:今天已推送过,跳过本次推送") return results else: - print(f"静默模式:今天首次推送") + print(f"推送窗口控制:今天首次推送") report_data = prepare_report_data(stats, failed_ids, new_titles, id_to_name, mode) @@ -3312,8 +3312,8 @@ def send_to_notifications( # 如果成功发送了任何通知,且启用了每天只推一次,则记录推送 if ( - CONFIG["SILENT_PUSH"]["ENABLED"] - and CONFIG["SILENT_PUSH"]["ONCE_PER_DAY"] + CONFIG["PUSH_WINDOW"]["ENABLED"] + and CONFIG["PUSH_WINDOW"]["ONCE_PER_DAY"] and any(results.values()) ): push_manager = PushRecordManager() diff --git a/readme.md b/readme.md index e0670c8..b2492fe 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ [![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-v2.4.2-green.svg?style=flat-square)](https://github.com/sansan0/TrendRadar) +[![Version](https://img.shields.io/badge/version-v2.4.3-green.svg?style=flat-square)](https://github.com/sansan0/TrendRadar) [![企业微信通知](https://img.shields.io/badge/企业微信-通知-00D4AA?style=flat-square)](https://work.weixin.qq.com/) [![Telegram通知](https://img.shields.io/badge/Telegram-通知-00D4AA?style=flat-square)](https://telegram.org/) @@ -133,12 +133,20 @@ platforms: | **当前榜单**
`current` | 📰 自媒体人/内容创作者 | 按时推送(默认每小时推送一次) | 当前榜单匹配新闻
+ 新增新闻区域 | 实时热点追踪
了解当前最火的内容 | | **增量监控**
`incremental` | 📈 投资者/交易员 | 有新增才推送 | 新出现的匹配频率词新闻 | 避免重复信息干扰
高频监控场景 | -**静默推送模式**: +**附加功能 - 推送时间窗口控制**(可选): -- **时间范围控制**:设定推送时间窗口(如 9:00-18:00),仅在指定时间内推送 -- **适用场景**: - - 时间内每次执行都推送 - - 时间范围内只推送一次 +此功能独立于上述三种推送模式,可与任意模式搭配使用: + +- **时间窗口限制**: 设定推送时间范围(如 9:00-18:00 或 20:00-22:00),只在指定时间内推送 +- **推送频率控制**: + - 窗口内多次推送: 时间窗口内每次执行都推送 + - 每天仅推送一次: 时间窗口内只推送一次(适合当日汇总或当前榜单模式) +- **典型场景**: + - 工作时间推送: 只在工作日 9:00-18:00 接收消息 + - 晚间汇总推送: 希望在晚上固定时间(如 20:00-22:00)收到汇总 + - 避免打扰: 防止非工作时间收到推送通知 + +> 提示: 此功能默认关闭,需在 `config/config.yaml` 中手动启用 `push_window.enabled` ### **精准内容筛选** @@ -461,9 +469,25 @@ GitHub 一键 Fork 即可使用,无需编程基础。 >**升级说明**: - **提示**:不要通过 **Sync fork** 更新本项目, 建议查看【历史更新】,明确具体的【升级方式】和【功能内容】 -- **小版本更新**:从 v2.x 升级到 v2.y, 用本项目的 `main.py` 代码替换你 fork 仓库中的对应文件 +- **小版本更新**:从 v2.x 升级到 v2.y, 用本项目的 `main.py` 代码替换你 fork 仓库中的对应文件 - **大版本升级**:从 v1.x 升级到 v2.y, 建议删除现有 fork 后重新 fork,这样更省力且避免配置冲突 +### 2025/10/10 - v2.4.3 + +> 感谢 [nidaye996](https://github.com/sansan0/TrendRadar/issues/98) 发现的体验问题 + +- **更新内容**: + - 重构"静默推送模式"命名为"推送时间窗口控制",提升功能理解度 + - 明确推送时间窗口作为可选附加功能,可与三种推送模式搭配使用 + - 改进注释和文档描述,使功能定位更加清晰 + +- **更新提示**: + - 这个仅仅是重构,可以不用升级 + + +
+👉 历史更新 + ### 2025/10/8 - v2.4.2 - **更新内容**: @@ -476,9 +500,6 @@ GitHub 一键 Fork 即可使用,无需编程基础。 - 建议使用【大版本更新】 -
-👉 历史更新 - ### 2025/10/2 - v2.4.0 **新增 ntfy 推送通知** @@ -547,7 +568,7 @@ GitHub 一键 Fork 即可使用,无需编程基础。 - **推送频率可选**:时间段内支持单次推送或多次推送 **更新提示**: -- 本功能默认关闭,需手动在 config.yaml 中开启静默推送模式 +- 本功能默认关闭,需手动在 config.yaml 中开启推送时间窗口控制 - 升级需同时更新 main.py 和 config.yaml 两个文件 ### 2025/08/27 - v2.0.4 @@ -695,9 +716,9 @@ frequency_words.txt 文件增加了一个【必须词】功能,使用 + 号 #### 手机端设置: 1. 打开企业微信 App → 进入目标内部群聊 - 2. 点击右上角"…"按钮 → 选择"群机器人" - 3. 点击"添加" → 点击"新建" → 设置机器人昵称 - 4. 复制 Webhook 地址,配置到上方的 GitHub Secret 中 + 2. 点击右上角"…"按钮 → 选择"消息推送" + 3. 点击"添加" → 名称输入"TrendRadar" + 4. 复制 Webhook 地址,点击保存,复制的内容配置到上方的 GitHub Secret 中 #### PC 端设置流程类似
@@ -1270,7 +1291,7 @@ flowchart TD H --> H2[📰 current - 当前榜单
定时推送最新榜单] H --> H3[📈 incremental - 增量监控
仅推送新增内容] - H1 --> I[可选:静默推送设置
⏰ 时间窗口控制] + H1 --> I[可选:推送时间窗口控制
⏰ 限制推送时间范围] H2 --> I H3 --> I diff --git a/version b/version index acdc3f1..6550da6 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.4.2 \ No newline at end of file +2.4.3 \ No newline at end of file