69 lines
3.2 KiB
Python
69 lines
3.2 KiB
Python
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)
|
||
|
||
zju_keys = ["浙大", "浙江大学", "章丰", "有为与有效", "王坚", "黑土地", "牧场", "蓝天", "AI驱动", "产业发展新逻辑"]
|
||
thu_keys = ["清华", "清华大学", "企业战略", "价值网", "战略转折点", "只有偏执狂", "创新者的窘境", "精益创业", "反脆弱", "第二曲线"]
|
||
|
||
zju_memos = [m for m in memos if any(k in m["content"] for k in zju_keys)]
|
||
thu_memos = [m for m in memos if any(k in m["content"] for k in thu_keys)]
|
||
|
||
def fmt_memos(ms):
|
||
lines = []
|
||
for m in ms:
|
||
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())
|
||
return "\n\n".join(lines)
|
||
|
||
zju_text = fmt_memos(zju_memos) or "(无浙大相关内容)"
|
||
thu_text = fmt_memos(thu_memos) or "(无清华相关内容)"
|
||
|
||
user_prompt = "以下是我在浙大和清华两所大学学习的记录,请分析两者之间的关联:\n\n"
|
||
user_prompt += "## 浙大学习内容\n\n" + zju_text + "\n\n"
|
||
user_prompt += "## 清华学习内容\n\n" + thu_text + "\n\n"
|
||
user_prompt += "请重点分析: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: cross-analysis\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_thu_cross_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-thu cross 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")
|