import sys, os 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.3) TZ_BJ = timezone(timedelta(hours=8)) memos = mc.list_memos(days=7) keywords = ["浙大", "浙江大学", "章丰", "有为与有效", "王坚", "黑土地", "牧场", "蓝天", "AI驱动", "产业发展新逻辑"] zju_memos = [m for m in memos if any(k in m["content"] for k in keywords)] 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] lines.append("- **[" + ts + "]** " + m["content"].strip()) prompt = "以下是我在浙大学习的相关灵感,请简要分析章丰老师课程的最新内容(1000字左右):\n\n" + "\n\n".join(lines) sp = "你是一个学习伙伴,对浙大课程内容进行简要分析。控制在1000字左右,输出纯Markdown。" result = llm.ask(system_prompt=sp, user_prompt=prompt) date = datetime.now(timezone.utc) now_bj = datetime.now(TZ_BJ) content = "---\ndate: " + date.strftime("%Y-%m-%d") + "\ntype: zju-brief\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_brief_" + 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 brief " + now_str], cwd=proj, capture_output=True, timeout=15) subprocess.run(["git", "push", "origin", "main"], cwd=proj, capture_output=True, timeout=30) print("Pushed")