From ac27c47fcfe1c5b924cbd690d829d35852e0b696 Mon Sep 17 00:00:00 2001 From: sansan <77180927+sansan0@users.noreply.github.com> Date: Wed, 6 Aug 2025 19:30:05 +0800 Subject: [PATCH] v2.0.3 --- main.py | 628 +++++++++++++++++++++++++++++++++++++++++++++--------- readme.md | 17 +- version | 2 +- 3 files changed, 543 insertions(+), 104 deletions(-) diff --git a/main.py b/main.py index e6cb66d..c664ee5 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ import requests import yaml -VERSION = "2.0.2" +VERSION = "2.0.3" # === 配置管理 === @@ -1410,142 +1410,576 @@ def render_html_content( - 频率词统计报告 + + 热点新闻分析 -

频率词统计报告

- """ +
+
+
热点新闻分析
+
+
+ 报告类型 + """ + # 处理报告类型显示 if is_daily_summary: if mode == "current": - html += "

报告类型: 当前榜单模式

" + html += "当前榜单" elif mode == "incremental": - html += "

报告类型: 增量模式

" + html += "增量模式" else: - html += "

报告类型: 当日汇总

" + html += "当日汇总" else: - html += "

报告类型: 实时分析

" + html += "实时分析" + + html += """
+
+
+ 新闻总数 + """ + + html += f"{total_titles} 条" + + # 计算筛选后的热点新闻数量 + hot_news_count = sum(len(stat["titles"]) for stat in report_data["stats"]) + + html += """ +
+
+ 热点新闻 + """ + + html += f"{hot_news_count} 条" + + html += """ +
+
+ 生成时间 + """ now = get_beijing_time() - html += f"

总标题数: {total_titles}

" - html += f"

生成时间: {now.strftime('%Y-%m-%d %H:%M:%S')}

" + html += now.strftime('%m-%d %H:%M') + html += """
+
+
+
+ +
""" + + # 处理失败ID错误信息 if report_data["failed_ids"]: html += """ -
-

请求失败的平台

-
    - """ +
    +
    ⚠️ 请求失败的平台
    +
      """ for id_value in report_data["failed_ids"]: - html += f"
    • {html_escape(id_value)}
    • " + html += f'
    • {html_escape(id_value)}
    • ' html += """ -
    -
    - """ +
+
""" - html += """ - - - - - - - - - """ + # 处理主要统计数据 + if report_data["stats"]: + total_count = len(report_data["stats"]) + + for i, stat in enumerate(report_data["stats"], 1): + count = stat["count"] + + # 确定热度等级 + if count >= 10: + count_class = "hot" + elif count >= 5: + count_class = "warm" + else: + count_class = "" - for i, stat in enumerate(report_data["stats"], 1): - formatted_titles = [] + escaped_word = html_escape(stat["word"]) + + html += f""" +
+
+
+
{escaped_word}
+
{count} 条
+
+
{i}/{total_count}
+
""" - for title_data in stat["titles"]: - formatted_title = format_title_for_platform("html", title_data) - formatted_titles.append(formatted_title) + # 处理每个词组下的新闻标题,给每条新闻标上序号 + for j, title_data in enumerate(stat["titles"], 1): + is_new = title_data.get("is_new", False) + new_class = "new" if is_new else "" + + html += f""" +
+
{j}
+
+
+ {html_escape(title_data["source_name"])}""" + + # 处理排名显示 + ranks = title_data.get("ranks", []) + if ranks: + min_rank = min(ranks) + max_rank = max(ranks) + rank_threshold = title_data.get("rank_threshold", 10) + + # 确定排名等级 + if min_rank <= 3: + rank_class = "top" + elif min_rank <= rank_threshold: + rank_class = "high" + else: + rank_class = "" + + if min_rank == max_rank: + rank_text = str(min_rank) + else: + rank_text = f"{min_rank}-{max_rank}" + + html += f'{rank_text}' + + # 处理时间显示 + time_display = title_data.get("time_display", "") + if time_display: + # 简化时间显示格式,将波浪线替换为~ + simplified_time = time_display.replace(" ~ ", "~").replace("[", "").replace("]", "") + html += f'{html_escape(simplified_time)}' + + # 处理出现次数 + count_info = title_data.get("count", 1) + if count_info > 1: + html += f'{count_info}次' + + html += """ +
+
""" + + # 处理标题和链接 + escaped_title = html_escape(title_data["title"]) + link_url = title_data.get("mobile_url") or title_data.get("url", "") + + if link_url: + escaped_url = html_escape(link_url) + html += f'{escaped_title}' + else: + html += escaped_title + + html += """ +
+
+
""" - escaped_word = html_escape(stat["word"]) - html += f""" -
- - - - - - - """ - - html += """ -
排名频率词出现次数占比相关标题
{i}{escaped_word}{stat['count']}{stat.get('percentage', 0)}%{"
".join(formatted_titles)}
- """ + html += """ +
""" + # 处理新增新闻区域 if report_data["new_titles"]: html += f""" -
-

🆕 本次新增热点新闻 (共 {report_data['total_new_count']} 条)

- """ +
+
本次新增热点 (共 {report_data['total_new_count']} 条)
""" for source_data in report_data["new_titles"]: escaped_source = html_escape(source_data["source_name"]) - html += f"

{escaped_source} ({len(source_data['titles'])} 条)

    " + titles_count = len(source_data["titles"]) + + html += f""" +
    +
    {escaped_source} · {titles_count}条
    """ - for title_data in source_data["titles"]: - title_data_copy = title_data.copy() - title_data_copy["is_new"] = False - formatted_title = format_title_for_platform("html", title_data_copy) - if "] " in formatted_title: - formatted_title = formatted_title.split("] ", 1)[1] - html += f"
  • {formatted_title}
  • " + # 为新增新闻也添加序号 + for idx, title_data in enumerate(source_data["titles"], 1): + ranks = title_data.get("ranks", []) + + # 处理新增新闻的排名显示 + rank_class = "" + if ranks: + min_rank = min(ranks) + if min_rank <= 3: + rank_class = "top" + elif min_rank <= title_data.get("rank_threshold", 10): + rank_class = "high" + + if len(ranks) == 1: + rank_text = str(ranks[0]) + else: + rank_text = f"{min(ranks)}-{max(ranks)}" + else: + rank_text = "?" - html += "
" + html += f""" +
+
{idx}
+
{rank_text}
+
+
""" + + # 处理新增新闻的链接 + escaped_title = html_escape(title_data["title"]) + link_url = title_data.get("mobile_url") or title_data.get("url", "") + + if link_url: + escaped_url = html_escape(link_url) + html += f'{escaped_title}' + else: + html += escaped_title + + html += """ +
+
+
""" - html += "
" + html += """ +
""" + + html += """ +
""" html += """ + + """ diff --git a/readme.md b/readme.md index 98e9bed..1c83b1f 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,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.0.2-green.svg?style=flat-square)](https://github.com/sansan0/TrendRadar) +[![Version](https://img.shields.io/badge/version-v2.0.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/) @@ -23,6 +23,8 @@ > 本项目以轻量,易部署为目标,主要处理 issues > > 遇到问题提 issues,或【硅基茶水间】公众号留言 +> +> **Fork** 的同时,如果觉得有帮助,请顺手点个 ⭐️ **Star**,感谢支持 ## ✨ 核心功能 @@ -72,10 +74,10 @@ GitHub 一键 Fork 即可使用,无需编程基础。 **典型场景:** 股市投资监控、品牌舆情追踪、行业动态关注、生活资讯获取 -**💡 提示:** 想要网页版?进入你的仓库 Settings → Pages,启用 GitHub Pages。比如我这里[TrendRadar](https://sansan0.github.io/TrendRadar/)。 +**💡 提示:** 想要**实时更新**的网页版?进入你的仓库 Settings → Pages,启用 GitHub Pages。比如我这里[TrendRadar](https://sansan0.github.io/TrendRadar/)。

- 最新推送效果 + 飞书推送效果

@@ -118,14 +120,17 @@ GitHub 一键 Fork 即可使用,无需编程基础。 - **小版本更新**:直接在 GitHub 网页编辑器中,用本项目的 `main.py` 代码替换你 fork 仓库中的对应文件 - **大版本升级**:从 v1.x 升级到 v2.0 建议删除现有 fork 后重新 fork,这样更省力且避免配置冲突 -### 2025/07/28 - v2.0.2 +### 2025/08/06 - v2.0.3 -- 重构代码 -- 解决版本号容易被遗漏修改的问题 +- 优化 github page 的网页版效果,方便移动端使用
👉 历史更新 +### 2025/07/28 - v2.0.2 + +- 重构代码 +- 解决版本号容易被遗漏修改的问题 ### 2025/07/27 - v2.0.1 diff --git a/version b/version index f93ea0c..6acdb44 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.2 \ No newline at end of file +2.0.3 \ No newline at end of file