Files
inspiration-collector/analyzers/zju_analysis.py
2026-06-13 16:47:59 +08:00

67 lines
2.8 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.

import sys, os, json
sys.path.insert(0, '/home/ubuntu/inspiration-collector')
from tools.config import load_secrets, get_output_dir
from tools.llm import DeepSeekClient
from tools.memos_client import MemosClient
from datetime import datetime, timezone, timedelta
import subprocess
secrets = load_secrets()
mc = MemosClient(secrets.get("memos_url", "http://localhost:5230"), secrets["memos_token"])
llm = DeepSeekClient(secrets["deepseek_api_key"], secrets.get("deepseek_model", "deepseek-chat"), temperature=0.5)
TZ_BJ = timezone(timedelta(hours=8))
memos = mc.list_memos(days=7)
keywords = ["浙大", "浙江大学", "章丰", "有为与有效", "王坚", "黑土地", "牧场", "蓝天", "AI驱动", "产业发展新逻辑"]
zju_memos = []
for m in memos:
content = m["content"]
if any(kw in content for kw in keywords):
zju_memos.append(m)
if not zju_memos:
print("未找到浙大相关灵感")
sys.exit(0)
lines = []
for m in zju_memos:
ct = m["created_at"]
try:
dt = datetime.fromisoformat(ct.replace("Z", "+00:00")) + timedelta(hours=8)
ts = dt.strftime("%m/%d %H:%M")
except:
ts = ct[:16]
line = "- **[" + ts + "]** " + m["content"].strip()
lines.append(line)
user_prompt = "以下是我在浙江大学学习期间记录的灵感,请基于此写一篇专题分析:\n\n" + "\n\n".join(lines)
user_prompt += "\n\n请重点分析1) 课程的核心内容 2) 推荐的书和人物的背景介绍 3) 这些知识如何与我的个人系统构建相结合"
system_prompt = """你是一个私人学习伙伴。用户正在浙江大学参加培训,以下是他记录的与学习相关的灵感。
请只分析这些内容,不要涉及其他话题。
要求引用原文、融会贯通、有实质内容不少于2000字。输出纯Markdown。"""
result = llm.ask(system_prompt=system_prompt, user_prompt=user_prompt)
date = datetime.now(timezone.utc)
now_bj = datetime.now(TZ_BJ)
content = "---\ndate: " + date.strftime("%Y-%m-%d") + "\ntype: zju-special\ntags: [浙大学习, 专题分析]\n---\n\n"
content += result
daily_dir = os.path.join(get_output_dir("daily"), date.strftime("%Y-%m-%d"))
os.makedirs(daily_dir, exist_ok=True)
now_str = now_bj.strftime("%H%M%S")
fname = date.strftime("%Y-%m-%d") + "_zju_analysis_" + now_str + ".md"
fpath = os.path.join(daily_dir, fname)
with open(fpath, "w", encoding="utf-8") as f:
f.write(content)
print("Done: " + fpath + " (" + str(len(result)) + " chars)")
proj = "/home/ubuntu/inspiration-collector"
subprocess.run(["git", "add", fpath], cwd=proj, capture_output=True, timeout=15)
subprocess.run(["git", "commit", "-m", "zju analysis " + now_str], cwd=proj, capture_output=True, timeout=15)
subprocess.run(["git", "push", "origin", "main"], cwd=proj, capture_output=True, timeout=30)
print("Pushed to Gitea")