Files
inspiration-collector/tools/formatter.py

92 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Markdown formatter -- wraps AI-generated body with frontmatter and annotations."""
from datetime import datetime
def format_daily_digest(date, ai_body):
"""Wrap AI-generated Markdown body with frontmatter."""
date_str = date.strftime("%Y-%m-%d")
weekday = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"][date.weekday()]
lines = []
lines.append("---")
lines.append("date: " + date_str)
lines.append("type: daily-digest")
lines.append("tags: [灵感收集器, 每日总结]")
lines.append("---")
lines.append("")
lines.append("# " + date_str + " 灵感摘要 · " + weekday)
lines.append("")
lines.append("## AI 分析(自动生成,请勿编辑)")
lines.append("")
lines.append(ai_body)
lines.append("")
lines.append("---")
lines.append("")
lines.append("## 我的批注")
lines.append("")
lines.append("> *在这里写下你的想法、质疑、补充*")
lines.append("")
return "\n".join(lines)
def format_weekly_trend(start_date, end_date, stats, highlights, insight):
"""Format weekly trend markdown file."""
week_start = start_date.strftime("%m/%d")
week_end = end_date.strftime("%m/%d")
week_number = start_date.isocalendar()[1]
lines = []
lines.append("---")
lines.append("date: " + str(start_date.year) + "-W" + str(week_number))
lines.append("type: weekly-trend")
lines.append("tags: [灵感收集器, 每周趋势]")
lines.append("---")
lines.append("")
lines.append("# 第 " + str(week_number) + " 周灵感趋势(" + week_start + " - " + week_end + "")
lines.append("")
lines.append("## AI 分析(自动生成,请勿编辑)")
lines.append("")
lines.append("本周共记录 **" + str(stats.get('total', 0)) + "** 条灵感。")
lines.append("")
if stats.get("daily_counts"):
lines.append("### 每日活跃度")
lines.append("")
for day, count in stats["daily_counts"].items():
bar = "" * count if count > 0 else ""
lines.append("- " + day + "" + bar + " " + str(count) + "")
lines.append("")
if stats.get("categories"):
lines.append("### 主题分布")
lines.append("")
total = stats.get("total", 1)
for cat, count in stats["categories"].items():
pct = count / total * 100 if total else 0
lines.append("- **" + cat + "**" + str(count) + "条(" + str(int(pct)) + "%")
lines.append("")
if highlights:
lines.append("### 本周亮点")
lines.append("")
for h in highlights:
lines.append("- " + h)
lines.append("")
if insight:
lines.append("### 值得关注的模式")
lines.append("")
lines.append(insight)
lines.append("")
lines.append("---")
lines.append("")
lines.append("## 我的批注")
lines.append("")
lines.append("> *有什么想补充的写在下面*")
lines.append("")
return "\n".join(lines)