上传文件至 /
This commit is contained in:
111
resume_generation.py
Normal file
111
resume_generation.py
Normal file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
恢复中断的小说生成任务
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def find_unfinished_projects():
|
||||
"""查找未完成的项目"""
|
||||
base_dir = Path(__file__).parent
|
||||
unfinished = []
|
||||
|
||||
for item in base_dir.iterdir():
|
||||
if item.is_dir() and item.name.startswith('n') and item.name[1:].isdigit():
|
||||
progress_file = item / ".generation_progress.json"
|
||||
if progress_file.exists():
|
||||
try:
|
||||
with open(progress_file, 'r', encoding='utf-8') as f:
|
||||
progress = json.load(f)
|
||||
|
||||
if progress.get('stage') != 'complete':
|
||||
unfinished.append({
|
||||
'dir': item.name,
|
||||
'stage': progress.get('stage', 'unknown'),
|
||||
'progress': progress.get('progress_percent', 0),
|
||||
'last_update': progress.get('last_update', 'unknown')
|
||||
})
|
||||
except:
|
||||
continue
|
||||
|
||||
return sorted(unfinished, key=lambda x: x['last_update'], reverse=True)
|
||||
|
||||
def main():
|
||||
print("🔍 查找未完成的小说生成任务...")
|
||||
|
||||
unfinished = find_unfinished_projects()
|
||||
|
||||
if not unfinished:
|
||||
print("✅ 没有找到未完成的任务")
|
||||
print("💡 运行 python ViralNovel.py 开始新的生成")
|
||||
return
|
||||
|
||||
print(f"\n📋 找到 {len(unfinished)} 个未完成的任务:")
|
||||
print("-" * 60)
|
||||
|
||||
for i, proj in enumerate(unfinished, 1):
|
||||
print(f"{i}. 项目: {proj['dir']}")
|
||||
print(f" 阶段: {proj['stage']}")
|
||||
print(f" 进度: {proj['progress']:.1f}%")
|
||||
print(f" 更新: {proj['last_update']}")
|
||||
print()
|
||||
|
||||
if len(unfinished) == 1:
|
||||
choice = input("是否继续这个任务?(y/n): ").strip().lower()
|
||||
if choice == 'y':
|
||||
selected = unfinished[0]
|
||||
else:
|
||||
print("❌ 已取消")
|
||||
return
|
||||
else:
|
||||
try:
|
||||
choice = input(f"选择要继续的任务 (1-{len(unfinished)}): ").strip()
|
||||
idx = int(choice) - 1
|
||||
if 0 <= idx < len(unfinished):
|
||||
selected = unfinished[idx]
|
||||
else:
|
||||
print("❌ 无效选择")
|
||||
return
|
||||
except ValueError:
|
||||
print("❌ 请输入数字")
|
||||
return
|
||||
|
||||
print(f"\n🚀 继续生成任务: {selected['dir']}")
|
||||
print(f"📊 当前进度: {selected['stage']} ({selected['progress']:.1f}%)")
|
||||
print("⏳ 正在恢复...")
|
||||
|
||||
try:
|
||||
# 导入并运行恢复函数
|
||||
sys.path.append(str(Path(__file__).parent))
|
||||
from ViralNovel import resume_generation_from_progress
|
||||
|
||||
result = resume_generation_from_progress(selected['dir'])
|
||||
|
||||
print(f"\n✅ 生成完成!")
|
||||
print(f"📖 标题: {result['title']}")
|
||||
print(f"📁 保存位置: {result['project_dir']}")
|
||||
|
||||
except ImportError:
|
||||
print("❌ 无法导入 ViralNovel 模块")
|
||||
print("💡 请确保 ViralNovel.py 文件存在")
|
||||
|
||||
except Exception as e:
|
||||
error_str = str(e)
|
||||
print(f"\n❌ 恢复失败: {error_str}")
|
||||
|
||||
if "网络连接" in error_str or "超时" in error_str:
|
||||
print("\n🔧 网络问题解决建议:")
|
||||
print("1. 检查网络连接")
|
||||
print("2. 等待几分钟后重试")
|
||||
print("3. 运行: python resume_generation.py")
|
||||
|
||||
elif "rate limit" in error_str.lower():
|
||||
print("\n⏰ API调用频率限制:")
|
||||
print("1. 等待几分钟后重试")
|
||||
print("2. 运行: python resume_generation.py")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user