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.5) TZ_BJ = timezone(timedelta(hours=8)) memos = mc.list_memos(days=7) keywords = ["清华", "清华大学", "企业战略", "价值网", "战略转折点"] thu_memos = [] for m in memos: if any(kw in m["content"] for kw in keywords): thu_memos.append(m) if not thu_memos: print("未找到清华相关灵感") sys.exit(0) lines = [] for m in thu_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()) 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: thu-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") + "_thu_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", "thu 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")