#!/usr/bin/env python3 """ 第1章自动修复脚本 专门针对第1章的问题进行修复 """ import os import re import sys def load_chapter(filepath): """加载章节内容""" with open(filepath, 'r', encoding='utf-8') as f: return f.read() def save_chapter(filepath, content): """保存章节内容""" with open(filepath, 'w', encoding='utf-8') as f: f.write(content) def merge_short_paragraphs(content): """合并短段落""" lines = content.split('\n') result = [] buffer = [] for line in lines: stripped = line.strip() # 如果是空行,处理缓冲区 if not stripped: if buffer: # 合并缓冲区中的内容 merged = ' '.join(buffer).strip() result.append(merged) buffer = [] result.append('') # 保留空行 else: # 如果是标题,直接添加 if stripped.startswith('# '): if buffer: merged = ' '.join(buffer).strip() result.append(merged) buffer = [] result.append(stripped) else: # 检查是否是短段落 chinese_chars = len([c for c in stripped if '\u4e00' <= c <= '\u9fff']) if chinese_chars < 35: buffer.append(stripped) else: if buffer: merged = ' '.join(buffer).strip() result.append(merged) buffer = [] result.append(stripped) # 处理剩余的缓冲区 if buffer: merged = ' '.join(buffer).strip() result.append(merged) return '\n'.join(result) def add_golden_points(content): """增加爽点""" # 第1章需要的爽点 golden_points = [ # 1. 明确重生优势 "重生!这不是梦,是第二次机会。", # 2. 建立时间紧迫感 "六天,只有六天时间。六天后'稳盈宝'爆雷,八天后被扫地出门。", # 3. 展现先知优势 "他知道未来会发生什么。极寒末世,文明断层,但更重要的是,他知道哪些机会可以抓住。", # 4. 设置第一个目标 "第一个目标:用'稳盈宝'爆雷的消息,从周世昌那里换到启动资金。", # 5. 建立情绪释放点 "陈末握紧拳头,眼中闪过一丝狠厉。这一次,他不会再任人宰割。" ] # 在合适的位置插入爽点 lines = content.split('\n') result = [] inserted_count = 0 for line in lines: result.append(line) # 在关键位置插入爽点 if inserted_count < len(golden_points): if "重生后的第一场豪赌" in line and inserted_count == 0: result.append(golden_points[0]) inserted_count += 1 elif "时间,比任何人想象的都要紧迫" in line and inserted_count == 1: result.append(golden_points[1]) inserted_count += 1 elif "他知道这步棋的风险" in line and inserted_count == 2: result.append(golden_points[2]) inserted_count += 1 elif "第一步,找到周世昌" in line and inserted_count == 3: result.append(golden_points[3]) inserted_count += 1 elif "重生后的第一场豪赌,开始了" in line and inserted_count == 4: result.append(golden_points[4]) inserted_count += 1 # 如果没找到插入点,在结尾添加 if inserted_count < 3: result.append("\n" + "\n".join(golden_points[inserted_count:3])) return '\n'.join(result) def add_dialogue(content): """增加对话""" # 第1章可以增加的对话 dialogues = [ # 房东王姐的电话对话 "电话接通,房东王姐不耐烦的声音传来:'小陈,房租到底什么时候交?这周五是最后期限,不然我真要清房了。'", "陈末深吸一口气,声音平静:'王姐,周五之前我一定交。再给我几天时间。'", "'几天?我都给你宽限多久了?'王姐的声音提高,'这次说到做到,周五见不到钱,你的东西全扔出去!'", "电话挂断,忙音在耳边回响。陈末放下手机,眼神冰冷。", # 内心独白(可以处理为对话形式) "一个声音在心底响起:'陈末,你只有这一次机会。抓住它,或者重蹈覆辙。'", "他握紧拳头,低声自语:'这一次,我不会输。'" ] # 寻找插入对话的位置 lines = content.split('\n') result = [] for line in lines: result.append(line) # 在房东王姐相关的位置插入对话 if "房东王姐的短信" in line: result.append("") # 空行 result.append(dialogues[0]) result.append(dialogues[1]) result.append(dialogues[2]) result.append(dialogues[3]) # 在关键决策点插入内心独白 elif "重生后的第一场豪赌,开始了" in line: result.append("") # 空行 result.append(dialogues[4]) result.append(dialogues[5]) return '\n'.join(result) def enhance_emotional_arc(content): """增强情绪弧线""" # 情绪变化的关键点 emotional_beats = [ # 1. 开篇:迷茫、恐惧 "冷。不仅是身体的冷,更是从心底蔓延出来的寒意。那些记忆,那些死亡,是真的吗?", # 2. 确认重生:震惊、混乱 "镜子里的脸年轻,眼神却沧桑。两种时间在身体里冲撞,撕裂感让他几乎站立不稳。", # 3. 清算现状:绝望、压力 "十五万的债务,八天后的流落街头。数字像巨石压在胸口,呼吸都变得困难。", # 4. 制定计划:冷静、决绝 "恐惧慢慢沉淀,转化为冰冷的计算。如果那些记忆是真的,那么眼前的困境,不过是一场游戏的开始。", # 5. 决定行动:坚定、孤注一掷 "眼神从迷茫转为锐利。这一次,他要做执棋者,而不是棋子。" ] lines = content.split('\n') result = [] inserted = 0 for i, line in enumerate(lines): result.append(line) # 在情绪转折点插入描述 if inserted < len(emotional_beats): if "不是梦" in line and inserted == 0: result.append(emotional_beats[0]) inserted += 1 elif "镜子里的人" in line and inserted == 1: result.append(emotional_beats[1]) inserted += 1 elif "接近十五万" in line and inserted == 2: result.append(emotional_beats[2]) inserted += 1 elif "如果那些记忆是真的" in line and inserted == 3: result.append(emotional_beats[3]) inserted += 1 elif "重生后的第一场豪赌" in line and inserted == 4: result.append(emotional_beats[4]) inserted += 1 return '\n'.join(result) def fix_common_issues(content): """修复常见问题""" # 1. 替换破折号 content = content.replace('——', '—') # 2. 修复对话格式 content = re.sub(r'["]([^"]+)["]', r'「\1」', content) # 3. 减少短句堆砌 lines = content.split('\n') result = [] for line in lines: stripped = line.strip() if stripped and len(stripped) < 10 and not stripped.endswith(('。', '!', '?', '」')): # 短句,尝试与下一句合并 continue else: result.append(line) return '\n'.join(result) def main(): """主函数""" if len(sys.argv) < 2: print("用法:python auto_fix_chapter1.py <章节文件路径> [输出文件路径]") sys.exit(1) input_file = sys.argv[1] output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.md', '_fixed.md') if not os.path.exists(input_file): print(f"错误:文件不存在 - {input_file}") sys.exit(1) print(f"开始修复第1章:{input_file}") # 加载内容 content = load_chapter(input_file) original_length = len(content) print(f"原始内容长度:{original_length} 字符") # 执行修复步骤 print("1. 合并短段落...") content = merge_short_paragraphs(content) print("2. 增加爽点...") content = add_golden_points(content) print("3. 增加对话...") content = add_dialogue(content) print("4. 增强情绪弧线...") content = enhance_emotional_arc(content) print("5. 修复常见问题...") content = fix_common_issues(content) # 保存结果 save_chapter(output_file, content) new_length = len(content) print(f"修复完成!") print(f"输出文件:{output_file}") print(f"新内容长度:{new_length} 字符") print(f"长度变化:{new_length - original_length} 字符") # 生成修复报告 report = { "original_file": input_file, "fixed_file": output_file, "length_change": new_length - original_length, "fixes_applied": [ "合并短段落", "增加爽点", "增加对话", "增强情绪弧线", "修复常见问题" ], "next_steps": [ "运行质量检查确认修复效果", "重新提交 inkos 审核", "监控后续章节质量" ] } report_file = output_file.replace('.md', '_report.json') import json with open(report_file, 'w', encoding='utf-8') as f: json.dump(report, f, ensure_ascii=False, indent=2) print(f"修复报告:{report_file}") if __name__ == "__main__": main()