{inspiration_html}
"""
return html
def generate_combined_html(posts_data: List[Dict]) -> str:
"""生成包含所有帖子的单一HTML(带标签页)"""
# 生成标签页按钮
tabs_html = ""
for i, post in enumerate(posts_data):
post_detail = post.get("帖子详情", {})
title = post_detail.get("title", "无标题")
active_class = "active" if i == 0 else ""
tabs_html += f'\n'
# 生成标签页内容
contents_html = ""
for i, post in enumerate(posts_data):
active_class = "active" if i == 0 else ""
content = generate_post_content_html(post)
contents_html += f"""
{content}
"""
html = f"""
How解构结果可视化
How 解构结果可视化
灵感点特征匹配分析
{tabs_html}
{contents_html}
"""
return html
def main():
"""主函数"""
# 输入输出路径
script_dir = Path(__file__).parent
project_root = script_dir.parent.parent
data_dir = project_root / "data" / "data_1117"
input_dir = data_dir / "当前帖子_how解构结果"
output_file = data_dir / "当前帖子_how解构结果_可视化.html"
print(f"读取 how 解构结果: {input_dir}")
# 获取所有 JSON 文件
json_files = list(input_dir.glob("*_how.json"))
print(f"找到 {len(json_files)} 个文件\n")
# 读取所有帖子数据
posts_data = []
for i, file_path in enumerate(json_files, 1):
print(f"读取文件 [{i}/{len(json_files)}]: {file_path.name}")
with open(file_path, "r", encoding="utf-8") as f:
post_data = json.load(f)
posts_data.append(post_data)
# 生成合并的 HTML
print(f"\n生成合并的 HTML...")
html_content = generate_combined_html(posts_data)
# 保存 HTML 文件
print(f"保存到: {output_file}")
with open(output_file, "w", encoding="utf-8") as f:
f.write(html_content)
print(f"\n完成! 可视化文件已保存")
print(f"请在浏览器中打开: {output_file}")
if __name__ == "__main__":
main()