"""Markdown formatter - converts AI analysis results to beautiful .md files.""" from datetime import datetime def format_daily_digest(date, categories, summary, connections, todos): """Format daily digest markdown file.""" date_str = date.strftime("%Y-%m-%d") weekday = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"][date.weekday()] lines = [] lines.append("---") lines.append(f"date: {date_str}") lines.append("type: daily-digest") lines.append("tags: [灵感收集器, 每日总结]") lines.append("---") lines.append("") lines.append(f"# {date_str} 灵感摘要 · {weekday}") lines.append("") # Summary lines.append("## AI 分析(自动生成,请勿编辑)") lines.append("") lines.append(summary) 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("## 我的批注") 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(f"date: {start_date.year}-W{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("") # Stats lines.append("## AI 分析(自动生成,请勿编辑)") lines.append("") lines.append(f"本周共记录 **{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(f"- {day}:{bar} {count}条") lines.append("") if stats.get("categories"): lines.append("### 主题分布") lines.append("") for cat, count in stats["categories"].items(): pct = count / stats["total"] * 100 if stats["total"] else 0 lines.append(f"- **{cat}**:{count}条({pct:.0f}%)") lines.append("") if highlights: lines.append("### 本周亮点") lines.append("") for h in highlights: lines.append(f"- {h}") lines.append("") if insight: lines.append("### 值得关注的模式") lines.append("") lines.append(insight) lines.append("") # User annotation lines.append("---") lines.append("") lines.append("## 我的批注") lines.append("") lines.append("> *有什么想补充的写在下面*") lines.append("") return "\n".join(lines)