You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
95 lines
2.4 KiB
#!/usr/bin/env python3
|
|
import json
|
|
import datetime
|
|
import os
|
|
import sys
|
|
|
|
def get_learning_plan():
|
|
"""读取学习计划"""
|
|
plan_path = "/root/.openclaw/workspace/code-generate/openclaw-learning-plan.json"
|
|
with open(plan_path, 'r', encoding='utf-8') as f:
|
|
return json.load(f)
|
|
|
|
def get_current_day():
|
|
"""获取当前是第几天(基于文件记录或从第1天开始)"""
|
|
state_file = "/root/.openclaw/workspace/code-generate/learning-state.json"
|
|
|
|
if os.path.exists(state_file):
|
|
with open(state_file, 'r', encoding='utf-8') as f:
|
|
state = json.load(f)
|
|
day = state.get('current_day', 1)
|
|
else:
|
|
day = 1
|
|
|
|
return day
|
|
|
|
def save_current_day(day):
|
|
"""保存当前天数"""
|
|
state_file = "/root/.openclaw/workspace/code-generate/learning-state.json"
|
|
with open(state_file, 'w', encoding='utf-8') as f:
|
|
json.dump({'current_day': day}, f, ensure_ascii=False, indent=2)
|
|
|
|
def generate_lesson_message(day, plan):
|
|
"""生成课程消息"""
|
|
total_days = len(plan['plan'])
|
|
|
|
if day > total_days:
|
|
# 7天计划完成后,开始推荐额外资源
|
|
return generate_extra_resources_message(day - total_days, plan)
|
|
|
|
lesson = plan['plan'][day - 1]
|
|
|
|
message = f"""✨ **OpenClaw 101 学习计划 - 第 {day}/{total_days} 天**
|
|
|
|
📚 **今日主题:{lesson['topic']}**
|
|
|
|
---
|
|
"""
|
|
|
|
for i, resource in enumerate(lesson['resources'], 1):
|
|
message += f"""🔗 **{i}. {resource['title']}**
|
|
📝 {resource['desc']}
|
|
🌐 {resource['url']}
|
|
|
|
"""
|
|
|
|
message += f"---\n💡 今天就先学习这些内容吧!明天继续第 {day + 1} 天的内容~"
|
|
|
|
return message
|
|
|
|
def generate_extra_resources_message(index, plan):
|
|
"""生成额外资源推荐"""
|
|
extra = plan['extra_resources']
|
|
resource = extra[index % len(extra)]
|
|
|
|
message = f"""🎉 **OpenClaw 101 7天计划已完成!**
|
|
|
|
现在开始为你推荐更多精选资源:
|
|
|
|
---
|
|
|
|
🔗 **{resource['title']}**
|
|
📝 {resource['desc']}
|
|
🌐 {resource['url']}
|
|
|
|
---
|
|
💡 每天都会为你推荐一个新资源!
|
|
"""
|
|
return message
|
|
|
|
def main():
|
|
plan = get_learning_plan()
|
|
day = get_current_day()
|
|
|
|
message = generate_lesson_message(day, plan)
|
|
|
|
# 输出消息,供外部调用发送
|
|
print(message)
|
|
|
|
# 保存下一天
|
|
save_current_day(day + 1)
|
|
|
|
return message
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|