Skip to content

⭐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 等渠道智能推送。

fix: 修复 AI 翻译/分析/筛选流多处数据一致性问题,升级至 v6.9.1

sansana03ec97223b8
diff --git a/README-EN.md b/README-EN.md
index 4d312a668f..e499a8d062 100644
--- a/README-EN.md
+++ b/README-EN.md
@@ -11,8 +11,10 @@ Deploy in <strong>30 seconds</strong> — Say goodbye to endless scrolling, only
[![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-v6.9.0-blue.svg)](https://github.com/sansan0/TrendRadar)
+[![Version](https://img.shields.io/badge/version-v6.9.1-blue.svg)](https://github.com/sansan0/TrendRadar)
[![MCP](https://img.shields.io/badge/MCP-v4.1.0-green.svg)](https://github.com/sansan0/TrendRadar)
+[![Docker Pulls](https://img.shields.io/docker/pulls/wantcat/trendradar?style=flat-square&logo=docker&logoColor=white&label=TrendRadar%20Pulls&color=2496ED)](https://hub.docker.com/r/wantcat/trendradar)
+[![Docker Pulls](https://img.shields.io/docker/pulls/wantcat/trendradar-mcp?style=flat-square&logo=docker&logoColor=white&label=MCP%20Pulls&color=2496ED)](https://hub.docker.com/r/wantcat/trendradar-mcp)
[![RSS](https://img.shields.io/badge/RSS-Feed_Support-orange.svg?style=flat-square&logo=rss&logoColor=white)](https://github.com/sansan0/TrendRadar)
[![AI Translation](https://img.shields.io/badge/AI-Multi--Language-purple.svg?style=flat-square)](https://github.com/sansan0/TrendRadar)
diff --git a/README.md b/README.md
index 6c36d0dbcc..bf5161e016 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,10 @@
[![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-v6.9.0-blue.svg)](https://github.com/sansan0/TrendRadar)
+[![Version](https://img.shields.io/badge/version-v6.9.1-blue.svg)](https://github.com/sansan0/TrendRadar)
[![MCP](https://img.shields.io/badge/MCP-v4.1.0-green.svg)](https://github.com/sansan0/TrendRadar)
+[![Docker Pulls](https://img.shields.io/docker/pulls/wantcat/trendradar?style=flat-square&logo=docker&logoColor=white&label=TrendRadar%20Pulls&color=2496ED)](https://hub.docker.com/r/wantcat/trendradar)
+[![Docker Pulls](https://img.shields.io/docker/pulls/wantcat/trendradar-mcp?style=flat-square&logo=docker&logoColor=white&label=MCP%20Pulls&color=2496ED)](https://hub.docker.com/r/wantcat/trendradar-mcp)
[![RSS](https://img.shields.io/badge/RSS-订阅源支持-orange.svg?style=flat-square&logo=rss&logoColor=white)](https://github.com/sansan0/TrendRadar)
[![AI翻译](https://img.shields.io/badge/AI-多语言推送-purple.svg?style=flat-square)](https://github.com/sansan0/TrendRadar)
diff --git a/pyproject.toml b/pyproject.toml
index 76c7ac69df..28face9e7d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "trendradar"
-version = "6.9.0"
+version = "6.9.1"
description = "TrendRadar - 热点新闻聚合与分析工具"
requires-python = ">=3.12"
dependencies = [
diff --git a/trendradar/__init__.py b/trendradar/__init__.py
index 16d616d630..966054085b 100644
--- a/trendradar/__init__.py
+++ b/trendradar/__init__.py
@@ -9,5 +9,5 @@ TrendRadar - 热点新闻聚合与分析工具
from trendradar.context import AppContext
-__version__ = "6.9.0"
+__version__ = "6.9.1"
__all__ = ["AppContext", "__version__"]
diff --git a/trendradar/__main__.py b/trendradar/__main__.py
index 81cb5e63be..d34a8866f1 100644
--- a/trendradar/__main__.py
+++ b/trendradar/__main__.py
@@ -535,14 +535,22 @@ class NewsAnalyzer:
else:
ai_report_type = report_type
+ # 独立 AI 模式(ai_mode != 推送 mode)下,rss_items/standalone_data 仍是推送 mode 的数据,
+ # 与 ai_mode 的热榜 ai_stats 不同源。为避免时间窗错配的数据误导分析,独立模式下不向 AI
+ # 传入 RSS/独立展示区,使其专注于 ai_mode 的热榜分析(同 mode 时正常传入)。
+ ai_rss_stats = rss_items if ai_mode == mode else None
+ ai_standalone = standalone_data if ai_mode == mode else None
+ if ai_mode != mode and (rss_items or standalone_data):
+ print(f"[AI] 独立分析模式({ai_mode}):RSS/独立展示区与推送模式({mode})不同源,本次分析仅聚焦热榜")
+
result = analyzer.analyze(
stats=ai_stats,
- rss_stats=rss_items,
+ rss_stats=ai_rss_stats,
report_mode=ai_mode,
report_type=ai_report_type,
platforms=platforms,
keywords=keywords,
- standalone_data=standalone_data,
+ standalone_data=ai_standalone,
)
# 设置 AI 分析使用的模式
@@ -805,7 +813,7 @@ class NewsAnalyzer:
standalone_data: Optional[Dict] = None,
schedule: ResolvedSchedule = None,
rss_new_urls: Optional[set] = None,
- ) -> Tuple[List[Dict], Optional[str], Optional[AIAnalysisResult], Optional[List[Dict]]]:
+ ) -> Tuple[List[Dict], Optional[str], Optional[AIAnalysisResult], Optional[List[Dict]], Optional[Dict], Optional[List[Dict]]]:
"""统一的分析流水线:数据处理 → 统计计算(关键词/AI筛选)→ AI分析 → HTML生成"""
# 根据筛选策略选择数据处理方式
@@ -817,15 +825,16 @@ class NewsAnalyzer:
if ai_filter_result and ai_filter_result.success:
print(f"[筛选] AI 筛选完成: {ai_filter_result.total_matched} 条匹配, {len(ai_filter_result.tags)} 个标签")
# 转换为与关键词匹配相同的数据结构
- stats, ai_rss_stats = self.ctx.convert_ai_filter_to_report_data(
+ stats, ai_rss_stats, ai_rss_new_stats = self.ctx.convert_ai_filter_to_report_data(
ai_filter_result, mode=mode,
new_titles=new_titles, rss_new_urls=rss_new_urls,
)
total_titles = sum(len(titles) for titles in data_source.values())
- # AI 筛选的 RSS 结果替换关键词匹配的 RSS 结果
- if ai_rss_stats:
- rss_items = ai_rss_stats
+ # AI 筛选成功:无条件用 AI 结果替换 RSS 主区与新增区(与热榜 stats 一致,
+ # 不因 AI 命中为空而回退到关键词结果)
+ rss_items = ai_rss_stats
+ rss_new_items = ai_rss_new_stats
else:
# AI 筛选失败,回退到关键词匹配
error_msg = ai_filter_result.error if ai_filter_result else "未知错误"
@@ -866,21 +875,32 @@ class NewsAnalyzer:
standalone_data=standalone_data
)
- # 翻译 RSS 内容(如果启用)— 在 HTML 生成前执行,确保网页版也能展示翻译内容
- # 注意:仅翻译 rss_items 和 rss_new_items,不翻译 standalone_data(通知前会重新生成)
+ # 翻译 RSS 和独立展示区内容(如果启用)— 在 HTML 生成前执行,确保网页版也能展示翻译内容
+ # standalone_data 在此翻译一次后贯穿到推送阶段复用,避免重复翻译并保证网页与推送译文一致
# 热榜翻译在推送时由 dispatch_all 处理 report_data
trans_config = self.ctx.config.get("AI_TRANSLATION", {})
+ translate_report_func = None # 供 HTML 翻译热榜 report_data(在过滤之后翻译)
if trans_config.get("ENABLED", False):
dispatcher = self.ctx.create_notification_dispatcher()
display_regions = self.ctx.config.get("DISPLAY", {}).get("REGIONS", {})
- _, rss_items, rss_new_items, _ = \
+ _, rss_items, rss_new_items, standalone_data = \
dispatcher.translate_content(
report_data={"stats": [], "new_titles": []},
rss_items=rss_items,
rss_new_items=rss_new_items,
+ standalone_data=standalone_data,
display_regions=display_regions,
)
+ # 热榜 report_data 翻译回调:HTML 在 prepare_report_data 过滤之后调用,
+ # 仅翻译热榜(skip_rss/skip_standalone 跳过已在上游翻译的 RSS/独立区),网页版热榜展示译文
+ def translate_report_func(rd, _d=dispatcher, _r=display_regions):
+ translated_rd, _, _, _ = _d.translate_content(
+ report_data=rd, display_regions=_r,
+ skip_rss=True, skip_standalone=True,
+ )
+ return translated_rd
+
# 计算 RSS 匹配条数(供 HTML 和推送共用)
self._rss_matched_count = sum(stat.get("count", 0) for stat in rss_items) if rss_items else 0
@@ -911,9 +931,10 @@ class NewsAnalyzer:
"rss_source_total": self._rss_source_total,
"rss_source_failed": self._rss_source_failed,
},
+ translate_report_func=translate_report_func,
)
- return stats, html_file, ai_result, rss_items
+ return stats, html_file, ai_result, rss_items, standalone_data, rss_new_items
def _send_notification_if_needed(
self,
@@ -978,7 +999,8 @@ class NewsAnalyzer:
if ai_config.get("ENABLED", False):
ai_result = self._run_ai_analysis(
stats, rss_items, mode, report_type, id_to_name,
- current_results=current_results, schedule=schedule
+ current_results=current_results, schedule=schedule,
+ standalone_data=standalone_data,
)
# 准备报告数据
@@ -1382,13 +1404,6 @@ class NewsAnalyzer:
quiet=True,
)
- # 首次抓取时全部条目都是新增,清除新增统计以避免与主区域完全重复
- if rss_new_stats and rss_stats:
- main_count = sum(len(s.get("titles", [])) for s in rss_stats)
- new_count = sum(len(s.get("titles", [])) for s in rss_new_stats)
- if new_count > 0 and new_count >= main_count:
- rss_new_stats = None
-
self._rss_total_count = total
return rss_stats, rss_new_stats, raw_rss_items, rss_new_urls
@@ -1568,6 +1583,7 @@ class NewsAnalyzer:
stats = []
ai_result = None
title_info = None
+ standalone_data = None
# current 模式需要使用完整的历史数据
if self.report_mode == "current":
@@ -1592,7 +1608,7 @@ class NewsAnalyzer:
all_results, historical_id_to_name, historical_title_info, raw_rss_items
)
- stats, html_file, ai_result, rss_items = self._run_analysis_pipeline(
+ stats, html_file, ai_result, rss_items, standalone_data, rss_new_items = self._run_analysis_pipeline(
all_results,
self.report_mode,
historical_title_info,
@@ -1636,7 +1652,7 @@ class NewsAnalyzer:
all_results, historical_id_to_name, historical_title_info, raw_rss_items
)
- stats, html_file, ai_result, rss_items = self._run_analysis_pipeline(
+ stats, html_file, ai_result, rss_items, standalone_data, rss_new_items = self._run_analysis_pipeline(
all_results,
self.report_mode,
historical_title_info,
@@ -1664,7 +1680,7 @@ class NewsAnalyzer:
standalone_data = self._prepare_standalone_data(
results, id_to_name, title_info, raw_rss_items
)
- stats, html_file, ai_result, rss_items = self._run_analysis_pipeline(
+ stats, html_file, ai_result, rss_items, standalone_data, rss_new_items = self._run_analysis_pipeline(
results,
self.report_mode,
title_info,
@@ -1686,7 +1702,7 @@ class NewsAnalyzer:
standalone_data = self._prepare_standalone_data(
results, id_to_name, title_info, raw_rss_items
)
- stats, html_file, ai_result, rss_items = self._run_analysis_pipeline(
+ stats, html_file, ai_result, rss_items, standalone_data, rss_new_items = self._run_analysis_pipeline(
results,
self.report_mode,
title_info,
@@ -1709,9 +1725,8 @@ class NewsAnalyzer:
# 发送通知
if mode_strategy["should_send_notification"]:
- standalone_data = self._prepare_standalone_data(
- results, id_to_name, title_info, raw_rss_items
- )
+ # standalone_data 已在分析流水线中翻译,直接复用(不再重新 prepare 原文,
+ # 避免覆盖译文、避免重复翻译,并保证网页报告与推送译文一致)
self._send_notification_if_needed(
stats,
mode_strategy["report_type"],
diff --git a/trendradar/ai/filter.py b/trendradar/ai/filter.py
index 0c603e1be5..d0c90e1b35 100644
--- a/trendradar/ai/filter.py
+++ b/trendradar/ai/filter.py
@@ -312,7 +312,7 @@ class AIFilter:
titles: List[Dict],
tags: List[Dict],
interests_content: str = "",
- ) -> List[Dict]:
+ ) -> Optional[List[Dict]]:
"""
阶段 B:对一批新闻标题做分类
@@ -322,14 +322,15 @@ class AIFilter:
interests_content: 用户的兴趣描述(含质量过滤要求)
Returns:
- [{"news_item_id": int, "tag_id": int, "relevance_score": float}, ...]
+ 成功返回 [{"news_item_id": int, "tag_id": int, "relevance_score": float}, ...](无匹配时为空列表);
+ 调用失败返回 None(用于区分"无匹配"与"调用失败",失败批次不标记已分析以便下次重试)
"""
if not titles or not tags:
return []
if not self.classify_user:
print("[AI筛选] 分类提示词模板为空")
- return []
+ return None
# 构建标签列表文本
tags_list = "\n".join(
@@ -380,7 +381,7 @@ class AIFilter:
return self._parse_classify_response(response, titles, tags)
except Exception as e:
print(f"[AI筛选] 分类请求失败: {type(e).__name__}: {e}")
- return []
+ return None
def _parse_classify_response(
self,
diff --git a/trendradar/ai/translator.py b/trendradar/ai/translator.py
index d821cb5cba..dee03f854b 100644
--- a/trendradar/ai/translator.py
+++ b/trendradar/ai/translator.py
@@ -253,14 +253,19 @@ class AITranslator:
if current_idx is not None:
results.append((current_idx, "\n".join(current_text).strip()))
- # 按索引排序并提取文本
- results.sort(key=lambda x: x[0])
- translated = [text for _, text in results]
- raw_parsed_count = len(translated)
-
- # 如果解析结果数量不匹配,尝试简单按行分割
- if len(translated) != expected_count:
- # 回退:按行分割(去除编号)
+ # 基于 AI 返回的真实编号精确回填,而非位置顺序,避免 AI 漏号/乱序时整体错位
+ raw_parsed_count = len(results)
+
+ if results:
+ # 编号 i(1-based) 对应位置 i-1;缺失的编号位置留空(由上层保留原文),
+ # 不让后续译文顶替到相邻标题上
+ idx_to_text = {}
+ for idx, text in results:
+ if 1 <= idx <= expected_count:
+ idx_to_text[idx] = text
+ translated = [idx_to_text.get(i + 1, "") for i in range(expected_count)]
+ else:
+ # AI 未使用 [编号] 格式:回退为按行顺序提取
translated = []
for line in lines:
stripped = line.strip()
diff --git a/trendradar/context.py b/trendradar/context.py
index b4b0c10cac..d9c43d1ad5 100644
--- a/trendradar/context.py
+++ b/trendradar/context.py
@@ -319,6 +319,7 @@ class AppContext:
standalone_data: Optional[Dict] = None,
frequency_file: Optional[str] = None,
report_metadata: Optional[Dict] = None,
+ translate_report_func: Optional[Any] = None,
) -> str:
"""生成HTML报告"""
return generate_html_report(
@@ -335,6 +336,7 @@ class AppContext:
time_filename=self.format_time(),
render_html_func=lambda *args, **kwargs: self.render_html(*args, rss_items=rss_items, rss_new_items=rss_new_items, ai_analysis=ai_analysis, standalone_data=standalone_data, **kwargs),
report_metadata=report_metadata,
+ translate_report_func=translate_report_func,
)
def render_html(
@@ -749,6 +751,7 @@ class AppContext:
batch_count = 0 # 跨热榜和 RSS 的全局批次计数
# 处理热榜
+ succeeded_news_ids = [] # 成功分类(含无匹配)的热榜 id;仅这些标记已分析,失败批次留待重试
for i in range(0, len(pending_news), batch_size):
if batch_count > 0 and batch_interval > 0:
import time
@@ -760,13 +763,19 @@ class AppContext:
for n in batch
]
batch_results = ai_filter.classify_batch(titles_for_ai, active_tags, interests_content)
+ batch_count += 1
+ if batch_results is None:
+ # 调用失败:不标记该批次已分析,留待下次运行重试,避免新闻静默丢失
+ print(f"[AI筛选] 热榜批次 {i // batch_size + 1}: {len(batch)} 条 → 分类失败,将在下次运行重试")
+ continue
for r in batch_results:
r["source_type"] = "hotlist"
total_results.extend(batch_results)
- batch_count += 1
+ succeeded_news_ids.extend(n["id"] for n in batch)
print(f"[AI筛选] 热榜批次 {i // batch_size + 1}: {len(batch)} 条 → {len(batch_results)} 条匹配")
# 处理 RSS
+ succeeded_rss_ids = [] # 成功分类(含无匹配)的 RSS id;仅这些标记已分析,失败批次留待重试
for i in range(0, len(pending_rss), batch_size):
if batch_count > 0 and batch_interval > 0:
import time
@@ -778,10 +787,15 @@ class AppContext:
for n in batch
]
batch_results = ai_filter.classify_batch(titles_for_ai, active_tags, interests_content)
+ batch_count += 1
+ if batch_results is None:
+ # 调用失败:不标记该批次已分析,留待下次运行重试
+ print(f"[AI筛选] RSS 批次 {i // batch_size + 1}: {len(batch)} 条 → 分类失败,将在下次运行重试")
+ continue
for r in batch_results:
r["source_type"] = "rss"
total_results.extend(batch_results)
- batch_count += 1
+ succeeded_rss_ids.extend(n["id"] for n in batch)
print(f"[AI筛选] RSS 批次 {i // batch_size + 1}: {len(batch)} 条 → {len(batch_results)} 条匹配")
# 6. 保存结果
@@ -791,26 +805,25 @@ class AppContext:
if debug and saved != len(total_results):
print(f"[AI筛选][DEBUG] !! 保存数量不一致: 期望 {len(total_results)}, 实际 {saved}(可能有重复记录被跳过)")
- # 6.5 记录所有已分析的新闻(匹配+不匹配,用于去重)
+ # 6.5 记录已分析的新闻(匹配+不匹配,用于去重)。仅记录成功分类的批次;
+ # 失败批次的 id 不写入,使其下次运行重新分类,避免 AI 抖动导致新闻静默丢失
matched_hotlist_ids = {r["news_item_id"] for r in total_results if r.get("source_type") == "hotlist"}
matched_rss_ids = {r["news_item_id"] for r in total_results if r.get("source_type") == "rss"}
- if pending_news:
- hotlist_ids = [n["id"] for n in pending_news]
+ if succeeded_news_ids:
storage.save_analyzed_news(
- hotlist_ids, "hotlist", effective_interests_file,
+ succeeded_news_ids, "hotlist", effective_interests_file,
current_hash, matched_hotlist_ids
)
- if pending_rss:
- rss_ids = [n["id"] for n in pending_rss]
+ if succeeded_rss_ids:
storage.save_analyzed_news(
- rss_ids, "rss", effective_interests_file,
+ succeeded_rss_ids, "rss", effective_interests_file,
current_hash, matched_rss_ids
)
- if pending_news or pending_rss:
- total_analyzed = len(pending_news) + len(pending_rss)
+ if succeeded_news_ids or succeeded_rss_ids:
+ total_analyzed = len(succeeded_news_ids) + len(succeeded_rss_ids)
total_matched = len(matched_hotlist_ids) + len(matched_rss_ids)
print(f"[AI筛选] 已记录 {total_analyzed} 条新闻分析状态 (匹配 {total_matched}, 不匹配 {total_analyzed - total_matched})")
@@ -937,12 +950,14 @@ class AppContext:
rss_new_urls: 新增 RSS 条目的 URL 集合,用于 is_new 检测
Returns:
- (hotlist_stats, rss_stats):
+ (hotlist_stats, rss_stats, rss_new_stats):
- hotlist_stats: 与 count_word_frequency() 产出格式一致
- rss_stats: 与 rss_items 格式一致
+ - rss_new_stats: RSS 新增区(rss_stats 中 is_new 的子集),与 rss_new_items 格式一致
"""
hotlist_stats = []
rss_stats = []
+ rss_new_stats = [] # AI 筛选的 RSS 新增区(is_new 子集),与关键词路径 rss_new_stats 对齐
max_news = self.config.get("MAX_NEWS_PER_KEYWORD", 0)
min_score = self.ai_filter_config.get("MIN_SCORE", 0)
@@ -1085,6 +1100,15 @@ class AppContext:
"position": tag_data.get("position", 9999),
"titles": rss_titles,
})
+ # 新增 RSS 区:仅保留本轮新增(is_new)的条目,供推送/HTML 的"RSS 新增"区块使用
+ new_rss_titles = [t for t in rss_titles if t.get("is_new")]
+ if new_rss_titles:
+ rss_new_stats.append({
+ "word": tag_name,
+ "count": len(new_rss_titles),
+ "position": tag_data.get("position", 9999),
+ "titles": new_rss_titles,
+ })
if mode == "current" and filtered_count > 0:
total_kept = sum(s["count"] for s in hotlist_stats)
@@ -1103,11 +1127,13 @@ class AppContext:
if priority_sort_enabled:
hotlist_stats.sort(key=lambda x: (x.get("position", 9999), -x["count"], x["word"]))
rss_stats.sort(key=lambda x: (x.get("position", 9999), -x["count"], x["word"]))
+ rss_new_stats.sort(key=lambda x: (x.get("position", 9999), -x["count"], x["word"]))
else:
hotlist_stats.sort(key=lambda x: (-x["count"], x.get("position", 9999), x["word"]))
rss_stats.sort(key=lambda x: (-x["count"], x.get("position", 9999), x["word"]))
+ rss_new_stats.sort(key=lambda x: (-x["count"], x.get("position", 9999), x["word"]))
- return hotlist_stats, rss_stats
+ return hotlist_stats, rss_stats, rss_new_stats
# === 资源清理 ===
diff --git a/trendradar/crawler/rss/fetcher.py b/trendradar/crawler/rss/fetcher.py
index 832c95dbdc..01addc8d9d 100644
--- a/trendradar/crawler/rss/fetcher.py
+++ b/trendradar/crawler/rss/fetcher.py
@@ -84,48 +84,6 @@ class RSSFetcher:
return session
- def _filter_by_freshness(
- self,
- items: List[RSSItem],
- feed: RSSFeedConfig,
- ) -> Tuple[List[RSSItem], int]:
- """
- 根据新鲜度过滤文章
-
- Args:
- items: 待过滤的文章列表
- feed: RSS 源配置
-
- Returns:
- (过滤后的文章列表, 被过滤的文章数)
- """
- # 如果全局禁用,直接返回
- if not self.freshness_enabled:
- return items, 0
-
- # 确定此 feed 的 max_age_days
- max_days = feed.max_age_days
- if max_days is None:
- max_days = self.default_max_age_days
-
- # 如果设为 0,禁用此 feed 的过滤
- if max_days == 0:
- return items, 0
-
- # 过滤逻辑:无发布时间的文章保留
- filtered = []
- for item in items:
- if not item.published_at:
- # 无发布时间,保留
- filtered.append(item)
- elif is_within_days(item.published_at, max_days, self.timezone):
- # 在指定天数内,保留
- filtered.append(item)
- # 否则过滤掉
-
- filtered_count = len(items) - len(filtered)
- return filtered, filtered_count
-
def fetch_feed(self, feed: RSSFeedConfig) -> Tuple[List[RSSItem], Optional[str]]:
"""
抓取单个 RSS 源
diff --git a/trendradar/notification/dispatcher.py b/trendradar/notification/dispatcher.py
index 644adc7488..f573efdda5 100644
--- a/trendradar/notification/dispatcher.py
+++ b/trendradar/notification/dispatcher.py
@@ -77,6 +77,7 @@ class NotificationDispatcher:
standalone_data: Optional[Dict] = None,
display_regions: Optional[Dict] = None,
skip_rss: bool = False,
+ skip_standalone: bool = False,
) -> tuple:
"""
翻译推送内容
@@ -87,7 +88,8 @@ class NotificationDispatcher:
rss_new_items: RSS 新增条目
standalone_data: 独立展示区数据
display_regions: 区域显示配置(不展示的区域跳过翻译)
- skip_rss: 跳过 RSS 和独立展示区翻译(当数据已在上游翻译过时使用)
+ skip_rss: 跳过普通 RSS 翻译(当 RSS 已在上游翻译过时使用)
+ skip_standalone: 跳过独立展示区翻译(当 standalone 已在上游翻译过时使用)
Returns:
tuple: (翻译后的 report_data, rss_items, rss_new_items, standalone_data)
@@ -138,19 +140,19 @@ class NotificationDispatcher:
titles_to_translate.append(title_data.get("title", ""))
title_locations.append(("rss_new_items", stat_idx, title_idx))
- # 5. 独立展示区 - 热榜平台
- if standalone_data and scope.get("STANDALONE", True) and display_regions.get("STANDALONE", False):
+ # 5. 独立展示区 - 热榜平台 + RSS 源
+ # 统一由 skip_standalone 控制;standalone RSS 是独立数据集,不应被 skip_rss 跳过
+ if not skip_standalone and standalone_data and scope.get("STANDALONE", True) and display_regions.get("STANDALONE", False):
for plat_idx, platform in enumerate(standalone_data.get("platforms", [])):
for item_idx, item in enumerate(platform.get("items", [])):
titles_to_translate.append(item.get("title", ""))
title_locations.append(("standalone_platforms", plat_idx, item_idx))
- # 6. 独立展示区 - RSS 源(跳过已翻译的)
- if not skip_rss:
- for feed_idx, feed in enumerate(standalone_data.get("rss_feeds", [])):
- for item_idx, item in enumerate(feed.get("items", [])):
- titles_to_translate.append(item.get("title", ""))
- title_locations.append(("standalone_rss", feed_idx, item_idx))
+ # 6. 独立展示区 - RSS 源
+ for feed_idx, feed in enumerate(standalone_data.get("rss_feeds", [])):
+ for item_idx, item in enumerate(feed.get("items", [])):
+ titles_to_translate.append(item.get("title", ""))
+ title_locations.append(("standalone_rss", feed_idx, item_idx))
if not titles_to_translate:
print("[翻译] 没有需要翻译的内容")
@@ -259,10 +261,10 @@ class NotificationDispatcher:
report_data, rss_items, rss_new_items, standalone_data, display_regions
)
else:
- # RSS 已翻译,仅翻译热榜 report_data 和独立展示区热榜部分
+ # RSS 和独立展示区均已在上游翻译过,仅翻译热榜 report_data
report_data, _, _, standalone_data = self.translate_content(
report_data, standalone_data=standalone_data, display_regions=display_regions,
- skip_rss=True,
+ skip_rss=True, skip_standalone=True,
)
# 飞书
diff --git a/trendradar/report/generator.py b/trendradar/report/generator.py
index f406dbb8ee..721915ac48 100644
--- a/trendradar/report/generator.py
+++ b/trendradar/report/generator.py
@@ -153,6 +153,7 @@ def generate_html_report(
time_filename: str = "",
render_html_func: Optional[Callable] = None,
report_metadata: Optional[Dict] = None,
+ translate_report_func: Optional[Callable] = None,
) -> str:
"""
生成 HTML 报告
@@ -197,6 +198,11 @@ def generate_html_report(
rank_threshold,
)
+ # 翻译热榜 report_data(stats/new_titles)——在 prepare_report_data 过滤之后翻译,
+ # 不影响新增热点区的 title 匹配过滤,使 HTML 网页版热榜也展示译文
+ if translate_report_func:
+ report_data = translate_report_func(report_data)
+
if report_metadata:
_METADATA_KEYS = {
"hotlist_total", "platform_total", "rss_matched_count",
diff --git a/uv.lock b/uv.lock
index fe801cbaa9..8bc2feebac 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1996,7 +1996,7 @@ wheels = [
[[package]]
name = "trendradar"
-version = "6.9.0"
+version = "6.9.1"
source = { editable = "." }
dependencies = [
{ name = "boto3" },
diff --git a/version b/version
index 6a1fccf930..b81ba511f6 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-6.9.0
\ No newline at end of file
+6.9.1
\ No newline at end of file