novel-doomsday-resurgence/tools/precise_shuangdian_removal.py

108 lines
3.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
精确移除爽点分析内容保留正常的心理描写
"""
import os
import re
CHAPTERS_DIR = "/root/.openclaw/workspace/projects/末日重生_囤货/chapters"
def precise_remove_shuangdian(content):
"""
精确移除爽点分析保留正常的心理描写
"""
lines = content.split('\n')
result_lines = []
i = 0
while i < len(lines):
line = lines[i]
# 1. 移除特定的爽点分析句子(精确匹配)
if '展现重生者的先知优势' in line or '利用未来信息获取利益' in line:
# 跳过这一行
i += 1
continue
# 2. 移除"谈判桌上,陈末掌握着对手的所有底牌"这一段
if '谈判桌上,陈末掌握着对手的所有底牌' in line:
# 跳过这一段通常3行
i += 3
continue
# 3. 检查是否是爽点标题行
if re.search(r'^#\s*【爽点[一二三四五六七八九十]?[:]', line):
# 跳过爽点标题行
i += 1
# 检查下一行是否是爽点内容
while i < len(lines) and lines[i].strip() and not lines[i].startswith('#') and not re.search(r'【爽点[一二三四五六七八九十]?[:]', lines[i]):
i += 1
continue
# 4. 保留正常的心理描写(如「一周后爆雷,这个消息值多少钱?」)
# 这些是正常的心理活动,不应该被移除
result_lines.append(line)
i += 1
# 重新组合内容
result = '\n'.join(result_lines)
# 5. 清理多余的空白行
result = re.sub(r'\n{3,}', '\n\n', result)
# 6. 确保章节以正确的标题结束
# 移除末尾可能遗留的爽点内容
lines = result.split('\n')
cleaned_lines = []
for line in lines:
if '【爽点:' in line and '重生者的先知优势' in line:
continue
cleaned_lines.append(line)
result = '\n'.join(cleaned_lines)
return result.strip()
def main():
print("精确移除爽点分析内容...")
chapter_files = [f for f in os.listdir(CHAPTERS_DIR) if f.endswith('.md')]
# 先检查哪些文件需要修复
for filename in sorted(chapter_files):
filepath = os.path.join(CHAPTERS_DIR, filename)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 检查是否有需要修复的内容
needs_fix = (
'展现重生者的先知优势' in content or
'谈判桌上,陈末掌握着对手的所有底牌' in content or
re.search(r'^#\s*【爽点[一二三四五六七八九十]?[:]', content, re.MULTILINE)
)
if needs_fix:
print(f"修复: {filename}")
# 创建备份
backup_path = filepath + '.precise.bak'
with open(backup_path, 'w', encoding='utf-8') as f:
f.write(content)
# 应用修复
fixed_content = precise_remove_shuangdian(content)
with open(filepath, 'w', encoding='utf-8') as f:
f.write(fixed_content)
print(f" ✓ 已精确修复")
else:
print(f"检查: {filename} ✓ 无需修复")
print("\n精确修复完成!")
if __name__ == '__main__':
main()