daily folder structure: each date gets its own directory
This commit is contained in:
@ -1,55 +1,26 @@
|
||||
"""Markdown formatter - converts AI analysis results to beautiful .md files."""
|
||||
"""Markdown formatter -- wraps AI-generated body with frontmatter and annotations."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def format_daily_digest(date, categories, summary, connections, todos):
|
||||
"""Format daily digest markdown file."""
|
||||
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(f"date: {date_str}")
|
||||
lines.append("date: " + date_str)
|
||||
lines.append("type: daily-digest")
|
||||
lines.append("tags: [灵感收集器, 每日总结]")
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append(f"# {date_str} 灵感摘要 · {weekday}")
|
||||
lines.append("# " + date_str + " 灵感摘要 · " + weekday)
|
||||
lines.append("")
|
||||
|
||||
# Summary
|
||||
lines.append("## AI 分析(自动生成,请勿编辑)")
|
||||
lines.append("")
|
||||
lines.append(summary)
|
||||
lines.append(ai_body)
|
||||
lines.append("")
|
||||
|
||||
# Categories
|
||||
if categories:
|
||||
lines.append("### 分类概览")
|
||||
lines.append("")
|
||||
for cat, items in categories.items():
|
||||
count = len(items) if isinstance(items, list) else items
|
||||
lines.append(f"- **{cat}**:{count}条")
|
||||
lines.append("")
|
||||
|
||||
# Connections
|
||||
if connections:
|
||||
lines.append("### 关联发现")
|
||||
lines.append("")
|
||||
for conn in connections:
|
||||
lines.append(f"- {conn}")
|
||||
lines.append("")
|
||||
|
||||
# Todos
|
||||
if todos:
|
||||
lines.append("### 待办")
|
||||
lines.append("")
|
||||
for todo in todos:
|
||||
lines.append(f"- [ ] {todo}")
|
||||
lines.append("")
|
||||
|
||||
# User annotation area
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append("## 我的批注")
|
||||
@ -68,18 +39,16 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
|
||||
lines = []
|
||||
lines.append("---")
|
||||
lines.append(f"date: {start_date.year}-W{week_number}")
|
||||
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(f"# 第 {week_number} 周灵感趋势({week_start} - {week_end})")
|
||||
lines.append("# 第 " + str(week_number) + " 周灵感趋势(" + week_start + " - " + week_end + ")")
|
||||
lines.append("")
|
||||
|
||||
# Stats
|
||||
lines.append("## AI 分析(自动生成,请勿编辑)")
|
||||
lines.append("")
|
||||
lines.append(f"本周共记录 **{stats.get('total', 0)}** 条灵感。")
|
||||
lines.append("本周共记录 **" + str(stats.get('total', 0)) + "** 条灵感。")
|
||||
lines.append("")
|
||||
|
||||
if stats.get("daily_counts"):
|
||||
@ -87,22 +56,23 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
lines.append("")
|
||||
for day, count in stats["daily_counts"].items():
|
||||
bar = "█" * count if count > 0 else "▏"
|
||||
lines.append(f"- {day}:{bar} {count}条")
|
||||
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 / stats["total"] * 100 if stats["total"] else 0
|
||||
lines.append(f"- **{cat}**:{count}条({pct:.0f}%)")
|
||||
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(f"- {h}")
|
||||
lines.append("- " + h)
|
||||
lines.append("")
|
||||
|
||||
if insight:
|
||||
@ -111,7 +81,6 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
lines.append(insight)
|
||||
lines.append("")
|
||||
|
||||
# User annotation
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append("## 我的批注")
|
||||
|
||||
Reference in New Issue
Block a user