54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""同步今天的日记到数据库"""
|
|
import os
|
|
import sys
|
|
import json
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'diary_system.settings')
|
|
sys.path.insert(0, '/root/.openclaw/workspace/diary-system/backend')
|
|
|
|
import django
|
|
django.setup()
|
|
|
|
from datetime import date
|
|
from diary.models import DiaryEntry
|
|
|
|
# 读取今天的日记文件
|
|
diary_path = '/root/.openclaw/workspace/memory/2026-04-14.md'
|
|
with open(diary_path, 'r') as f:
|
|
content = f.read()
|
|
|
|
# 解析日记内容(简单解析)
|
|
def extract_section(content, marker):
|
|
lines = content.split('\n')
|
|
result = []
|
|
in_section = False
|
|
for line in lines:
|
|
if marker in line:
|
|
in_section = True
|
|
continue
|
|
if in_section:
|
|
if line.startswith('## ') or line.startswith('---'):
|
|
break
|
|
result.append(line)
|
|
return '\n'.join(result).strip()
|
|
|
|
# 创建或更新日记
|
|
today = date.today()
|
|
entry, created = DiaryEntry.objects.get_or_create(date=today)
|
|
|
|
entry.title = "第一天 - 日记系统上线"
|
|
entry.completed_tasks = extract_section(content, '✅ 完成的任务')
|
|
entry.learned = extract_section(content, '📚 学到的东西')
|
|
entry.problems = extract_section(content, '🐛 遇到的问题')
|
|
entry.reflections = extract_section(content, '💡 想法和反思')
|
|
entry.improvements = extract_section(content, '📈 进步点')
|
|
entry.plans = extract_section(content, '🎯 明日计划')
|
|
entry.save()
|
|
|
|
print(f"✅ 日记已同步:{entry.date}")
|
|
print(f" 标题:{entry.title}")
|
|
print(f" 完成的任务:{len(entry.completed_tasks)} 字")
|
|
print(f" 学到的东西:{len(entry.learned)} 字")
|
|
print(f" 进步点:{len(entry.improvements)} 字")
|