#!/usr/bin/env python3 """ 最终质量检查脚本 检查章节格式是否已经修复 """ import os import re CHAPTERS_DIR = "/root/.openclaw/workspace/projects/末日重生_囤货/chapters" def check_chapter_quality(filename, content): """ 检查章节质量 返回问题列表 """ problems = [] # 1. 检查是否有爽点分析混入正文 if '展现重生者的先知优势' in content: problems.append("仍有'展现重生者的先知优势'在正文中") if '利用未来信息获取利益' in content: problems.append("仍有'利用未来信息获取利益'在正文中") if '谈判桌上,陈末掌握着对手的所有底牌' in content: problems.append("仍有重复的'谈判桌上'段落") # 2. 检查是否有爽点标题 if re.search(r'^#\s*【爽点[一二三四五六七八九十]?[::]', content, re.MULTILINE): problems.append("仍有爽点标题在正文中") # 3. 检查章节标题格式 if not content.startswith('# 第'): problems.append("章节标题格式不正确") # 4. 检查是否有HTML注释中的爽点分析 if '': skip = False continue if not skip: cleaned_lines.append(line) content = '\\n'.join(cleaned_lines) # 4. 确保章节标题格式正确 if not content.startswith('# 第'): # 从内容中提取章节标题 first_line = content.split('\\n')[0] if content else '' match = re.search(r'第(\\d+)章\\s+(.+)', first_line) if match: chapter_num = match.group(1) chapter_title = match.group(2) content = f'# 第{chapter_num}章 {chapter_title}\\n\\n' + '\\n'.join(content.split('\\n')[1:]) # 5. 清理多余的空白行 content = re.sub(r'\\n{3,}', '\\n\\n', content) return content.strip() # 需要修复的文件列表 problem_files = %s for filename in problem_files: filepath = os.path.join(CHAPTERS_DIR, filename) print(f"修复: {filename}") with open(filepath, 'r', encoding='utf-8') as f: content = f.read() # 创建备份 backup_path = filepath + '.final.bak' with open(backup_path, 'w', encoding='utf-8') as f: f.write(content) # 应用修复 fixed_content = final_fix_content(content) with open(filepath, 'w', encoding='utf-8') as f: f.write(fixed_content) print(f" ✓ 已修复") print("\\n所有文件修复完成!") """ % str([filename for filename, _ in problem_files]) script_path = os.path.join(CHAPTERS_DIR, "tools", "apply_final_fixes.py") with open(script_path, 'w', encoding='utf-8') as f: f.write(script_content) print(f"\n已创建修复脚本: tools/apply_final_fixes.py") print(f"运行命令: cd /root/.openclaw/workspace/projects/末日重生_囤货 && python3 tools/apply_final_fixes.py") if __name__ == '__main__': main()