"""
# 处理失败ID错误信息
if report_data["failed_ids"]:
html += """
⚠️ 请求失败的平台
"""
for id_value in report_data["failed_ids"]:
html += f'- {html_escape(id_value)}
'
html += """
"""
# 生成热点词汇统计部分的HTML
stats_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 = ""
escaped_word = html_escape(stat["word"])
stats_html += f"""
"""
# 处理每个词组下的新闻标题,给每条新闻标上序号
for j, title_data in enumerate(stat["titles"], 1):
is_new = title_data.get("is_new", False)
new_class = "new" if is_new else ""
stats_html += f"""
{j}
"""
# 处理标题和链接
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)
stats_html += f'
{escaped_title}'
else:
stats_html += escaped_title
stats_html += """
"""
stats_html += """
"""
# 生成新增新闻区域的HTML
new_titles_html = ""
if report_data["new_titles"]:
new_titles_html += f"""
本次新增热点 (共 {report_data['total_new_count']} 条)
"""
for source_data in report_data["new_titles"]:
escaped_source = html_escape(source_data["source_name"])
titles_count = len(source_data["titles"])
new_titles_html += f"""
{escaped_source} · {titles_count}条
"""
# 为新增新闻也添加序号
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 = "?"
new_titles_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)
new_titles_html += f'
{escaped_title}'
else:
new_titles_html += escaped_title
new_titles_html += """
"""
new_titles_html += """
"""
new_titles_html += """
"""
# 根据配置决定内容顺序
if reverse_content_order:
# 新增热点在前,热点词汇统计在后
html += new_titles_html + stats_html
else:
# 默认:热点词汇统计在前,新增热点在后
html += stats_html + new_titles_html
html += """