zhejiang 2-day narrative
This commit is contained in:
75
analyzers/zj_article.py
Normal file
75
analyzers/zj_article.py
Normal file
@ -0,0 +1,75 @@
|
||||
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'
|
||||
|
||||
# Get ALL memos from the past 2 days (Zhejiang trip)
|
||||
memos = mc.list_memos(days=2)
|
||||
|
||||
# Sort by time
|
||||
def parse_dt(m):
|
||||
try:
|
||||
return datetime.fromisoformat(m['created_at'].replace('Z','+00:00'))
|
||||
except:
|
||||
return datetime.now(timezone.utc)
|
||||
memos.sort(key=parse_dt)
|
||||
|
||||
lines = []
|
||||
for m in 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(f'[{ts}] ' + m['content'].strip())
|
||||
|
||||
full_text = '\n\n---\n\n'.join(lines)
|
||||
|
||||
sp = (
|
||||
'写一篇个人叙事文章,记录在浙江两天的学习与思考。\n\n'
|
||||
'要求:\n'
|
||||
'1. 以第一人称叙事,真实、克制,不做作,不煽情\n'
|
||||
'2. 按时间线展开——第一天(浙大章丰老师课程 → 科大讯飞参观 → 深夜搭建系统),第二天(浙大厉敏老师课程)\n'
|
||||
'3. 不只是记课程内容,更重在记录自己的内心变化、认知突破、系统构建的历程\n'
|
||||
'4. 引用具体的细节和感悟(如"人类成为了神"、"开枪开枪开枪"、"黑土地牧场蓝天"、"电力加算力"等),让文章有血肉\n'
|
||||
'5. 结尾收束到"此行之于我"的思考——这些知识如何与自己正在做的事交汇\n'
|
||||
'6. 篇幅3000-5000字\n'
|
||||
'7. 标题简洁有力,不花哨\n\n'
|
||||
'输出纯Markdown。'
|
||||
)
|
||||
|
||||
prompt = '以下是我在浙江两天(6月13日-14日)的全部灵感记录,请据此写一篇文章:\n\n' + full_text
|
||||
|
||||
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: zhejiang-narrative\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 = f'浙江两日记_{now_str}.md'
|
||||
fpath = os.path.join(daily_dir, fname)
|
||||
with open(fpath, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
print(f'Done: {fpath} ({cc} chars)')
|
||||
subprocess.run(['git','add','-A'], cwd=PROJ, capture_output=True, timeout=15)
|
||||
subprocess.run(['git','commit','-m','zhejiang 2-day narrative'], cwd=PROJ, capture_output=True, timeout=15)
|
||||
subprocess.run(['git','push','origin','main'], cwd=PROJ, capture_output=True, timeout=30)
|
||||
print('Pushed')
|
||||
Reference in New Issue
Block a user