Add daily report HTML to root directory for GitHub Pages support

This commit is contained in:
sansan 2025-04-30 08:04:09 +08:00
parent 3f481c107c
commit 7c990420a8

13
main.py
View File

@ -19,7 +19,7 @@ CONFIG = {
"RANK_THRESHOLD": 5, # 排名阈值,决定使用【】还是[]的界限 "RANK_THRESHOLD": 5, # 排名阈值,决定使用【】还是[]的界限
"USE_PROXY": False, # 是否启用本地代理 "USE_PROXY": False, # 是否启用本地代理
"DEFAULT_PROXY": "http://127.0.0.1:10086", "DEFAULT_PROXY": "http://127.0.0.1:10086",
"CONTINUE_WITHOUT_FEISHU": False, # 控制是否在没有飞书webhook URL时继续执行爬虫, 如果True ,会依然进行爬虫行为会在github上持续的生成爬取的新闻数据 "CONTINUE_WITHOUT_FEISHU": True, # 控制是否在没有飞书webhook URL时继续执行爬虫, 如果True ,会依然进行爬虫行为会在github上持续的生成爬取的新闻数据
"FEISHU_WEBHOOK_URL": "", # 飞书机器人的webhook URL大概长这样https://www.feishu.cn/flow/api/trigger-webhook/xxxx 默认为空推荐通过GitHub Secrets设置 "FEISHU_WEBHOOK_URL": "", # 飞书机器人的webhook URL大概长这样https://www.feishu.cn/flow/api/trigger-webhook/xxxx 默认为空推荐通过GitHub Secrets设置
} }
@ -673,7 +673,6 @@ class ReportGenerator:
) -> str: ) -> str:
""" """
生成HTML报告包括失败的请求信息 生成HTML报告包括失败的请求信息
Returns: Returns:
HTML文件路径 HTML文件路径
""" """
@ -682,7 +681,6 @@ class ReportGenerator:
filename = "当日统计.html" filename = "当日统计.html"
else: else:
filename = f"{TimeHelper.format_time_filename()}.html" filename = f"{TimeHelper.format_time_filename()}.html"
file_path = FileHelper.get_output_path("html", filename) file_path = FileHelper.get_output_path("html", filename)
# HTML模板和内容生成 # HTML模板和内容生成
@ -694,6 +692,15 @@ class ReportGenerator:
with open(file_path, "w", encoding="utf-8") as f: with open(file_path, "w", encoding="utf-8") as f:
f.write(html_content) f.write(html_content)
# 如果是当日统计还需要在根目录下生成index.html
if is_daily:
root_file_path = "index.html" # 根目录下使用index.html作为文件名
with open(root_file_path, "w", encoding="utf-8") as f:
f.write(html_content)
print(
f"当日统计报告已保存到根目录的index.html: {os.path.abspath(root_file_path)}"
)
return file_path return file_path
@staticmethod @staticmethod