Files
inspiration-collector/analyzers/zju_0614_v4.py

75 lines
3.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.

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))
PROJ = '/home/ubuntu/inspiration-collector'
memos = mc.list_memos(days=1)
keywords = ['厉敏','数字浙江','数字经济','一号工程','科技革命','产业变革','四次革命']
target = [m for m in memos if any(k in m['content'] for k in keywords)]
lines = []
for m in target:
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())
text = '\n\n'.join(lines)
sp = '''将以下课程学习记录整理成个人学习笔记。
要求:
1. 逻辑层次清晰,用自然分段和小标题体现结构,不要教科书式条目,也不要大段无层次文字
2. 对关键概念补充必要的背景信息(如技术革命的简要说明、人物背景等),让笔记有信息厚度
3. 开头记录客观信息:时间、地点、课程名称、授课老师(如有背景简介也写上)
4. 文风克制客观,不用第一人称和抒情,这是给自己看的笔记
5. 篇幅适中约1500-2000字
6. 【重要】记录中标记"""自己"等主观表述的,是用户自己的思考和感悟,不是课程内容。请区分课程内容和用户个人思考,用户思考部分可作为"延伸思考"单独标注,不要混入课程内容中。
输出纯Markdown。'''
teacher_bio = (
'【授课老师背景】\n'
'厉敏,曾任浙江省经济和信息化厅副厅长、党组成员,'
'长期分管浙江省信息化、数字经济及产业发展工作,'
'是浙江数字经济的主要谋划者和实践者,'
'主持浙江数字化改革和数字经济"一号工程"相关政策体系的制定与落地。'
)
prompt = '以下是在浙江大学学习的记录:\n\n' + text + '\n\n【授课老师背景】\n' + teacher_bio.strip()
result = llm.ask(system_prompt=sp, user_prompt=prompt)
cc = len(result.replace(' ','').replace('\n',''))
rm = max(1, round(cc/300))
content = '---\ndate: 2026-06-14\ntype: zju-analysis\ntags: [浙大, 学习分析]\n---\n\n'
content += '> 本文共 **' + str(cc) + '** 字 · 预计阅读 **' + str(rm) + '** 分钟\n\n'
content += result
daily_dir = os.path.join(get_output_dir('daily'), '2026-06-14')
os.makedirs(daily_dir, exist_ok=True)
now_str = datetime.now(TZ_BJ).strftime('%H%M%S')
fname = '01_浙大学习分析_v' + now_str + '.md'
fpath = os.path.join(daily_dir, fname)
with open(fpath, 'w') as f:
f.write(content)
print('Done: ' + fpath + ' (' + str(cc) + ' chars)')
subprocess.run(['git','add','-A'], cwd=PROJ, capture_output=True, timeout=15)
subprocess.run(['git','commit','-m','zju 0614 v4 with personal thought distinction'], cwd=PROJ, capture_output=True, timeout=15)
subprocess.run(['git','push','origin','main'], cwd=PROJ, capture_output=True, timeout=30)
print('Pushed')