Skip to content

Commit 2a3ae54

Browse files
committed
fix: 修复增量模式下无新闻却存在推送通知的情况
1 parent 97e0504 commit 2a3ae54

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

trendradar/__main__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ def _has_valid_content(
215215
) -> bool:
216216
"""检查是否有有效的新闻内容"""
217217
if self.report_mode == "incremental":
218-
# 增量模式:必须有新增标题才推送
218+
# 增量模式:必须有新增标题且匹配了关键词才推送
219219
has_new_titles = bool(
220220
new_titles and any(len(titles) > 0 for titles in new_titles.values())
221221
)
222-
return has_new_titles
222+
has_matched_news = any(stat["count"] > 0 for stat in stats)
223+
return has_new_titles and has_matched_news
223224
elif self.report_mode == "current":
224225
# current模式:只要stats有内容就说明有匹配的新闻
225226
return any(stat["count"] > 0 for stat in stats)
@@ -418,7 +419,13 @@ def _send_notification_if_needed(
418419
mode_strategy = self._get_mode_strategy()
419420
if "实时" in report_type:
420421
if self.report_mode == "incremental":
421-
print("跳过实时推送通知:增量模式下未检测到新增的新闻")
422+
has_new = bool(
423+
new_titles and any(len(titles) > 0 for titles in new_titles.values())
424+
)
425+
if not has_new:
426+
print("跳过实时推送通知:增量模式下未检测到新增的新闻")
427+
else:
428+
print("跳过实时推送通知:增量模式下新增新闻未匹配到关键词")
422429
else:
423430
print(
424431
f"跳过实时推送通知:{mode_strategy['mode_name']}下未检测到匹配的新闻"

0 commit comments

Comments
 (0)