dy-dashboard/daily_knowledge_note.py
2026-10-28 11:14:17 +08:00

48 lines
1.4 KiB
Python
Raw Permalink 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.

#!/usr/bin/env python3
"""每日知识笔记生成脚本 - 由 cron job 触发
从当天对话中提取知识沉淀,保存到 Obsidian 知识库。
"""
import os, json, subprocess
from datetime import datetime
VAULT_PATH = "/home/gxd/蝶雅供应链"
DATE = datetime.now().strftime("%Y-%m-%d")
# 训练笔记统一归入工作指南/训练记录(历史曾误生成到供应链流程,2026-08-10 修正)
TOPDIR = os.path.join(VAULT_PATH, "知识库", "工作指南", "训练记录")
def write_note(title, content):
"""写入知识库并更新索引"""
safe_name = title.replace('/', '-').replace(':', '-')
path = os.path.join(TOPDIR, f"{DATE}-{safe_name}.md")
full = f"""# {title}
> 来源:旭东与 OpenClaw 每日训练,{DATE}
> 类型:训练记录
{content}
---
*由 OpenClaw 每日训练任务自动生成*
"""
os.makedirs(TOPDIR, exist_ok=True)
with open(path, 'w', encoding='utf-8') as f:
f.write(full)
# Update log
log_path = os.path.join(VAULT_PATH, "知识库", "操作日志.md")
with open(log_path, 'a', encoding='utf-8') as f:
f.write(f"\n## [{DATE}] 编译 | {title}\n")
f.write(f"- 由每日训练任务自动生成\n")
return path
if __name__ == '__main__':
import sys
title = sys.argv[1] if len(sys.argv) > 1 else f"每日训练记录-{DATE}"
content = sys.stdin.read()
path = write_note(title, content)
print(f"✅ 笔记已保存: {path}")