175 lines
5.1 KiB
Python
175 lines
5.1 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
"""
|
|||
|
|
全面改进章节标题
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import os
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
CHAPTERS_DIR = "/root/.openclaw/workspace/projects/末日重生_囤货/chapters"
|
|||
|
|
|
|||
|
|
# 优质标题建议(根据番茄小说调性)
|
|||
|
|
GOOD_TITLES = {
|
|||
|
|
# 原标题 -> 改进标题
|
|||
|
|
'仓鼠行动': '仓鼠行动',
|
|||
|
|
'粮草先行': '粮草先行',
|
|||
|
|
|
|||
|
|
# 增加吸引力的改进
|
|||
|
|
'铁壁': '铁壁防线',
|
|||
|
|
'焊花': '焊花飞舞',
|
|||
|
|
'骨刺': '骨刺危机',
|
|||
|
|
'暗流(2)': '暗流再起',
|
|||
|
|
'质询': '致命质询',
|
|||
|
|
'断水': '水源危机',
|
|||
|
|
'昏沉': '意识迷途',
|
|||
|
|
'电话': '致命来电',
|
|||
|
|
'赴约': '死亡之约',
|
|||
|
|
'充电': '能量重启',
|
|||
|
|
'交付': '生死交付',
|
|||
|
|
'对峙(2)': '生死对峙',
|
|||
|
|
'决断': '生死决断',
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
def analyze_current_titles():
|
|||
|
|
"""分析当前所有标题"""
|
|||
|
|
chapter_files = [f for f in os.listdir(CHAPTERS_DIR) if f.endswith('.md')]
|
|||
|
|
|
|||
|
|
results = []
|
|||
|
|
|
|||
|
|
for filename in chapter_files:
|
|||
|
|
match = re.search(r'ch(\d+)-第\d+章\s+(.+)\.md', filename)
|
|||
|
|
if not match:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
chapter_num = match.group(1)
|
|||
|
|
title = match.group(2)
|
|||
|
|
|
|||
|
|
# 评估标题质量
|
|||
|
|
score = 100
|
|||
|
|
|
|||
|
|
# 检查下划线
|
|||
|
|
if '_' in title:
|
|||
|
|
score -= 25
|
|||
|
|
|
|||
|
|
# 检查括号数字
|
|||
|
|
if '(' in title and ')' in title:
|
|||
|
|
score -= 25
|
|||
|
|
|
|||
|
|
# 检查技术词汇
|
|||
|
|
|
|||
|
|
tech_words = ['修复', 'fixed', '备份']
|
|||
|
|
for word in tech_words:
|
|||
|
|
if word in title:
|
|||
|
|
score -= 30
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 检查长度
|
|||
|
|
if len(title) < 2:
|
|||
|
|
score -= 20
|
|||
|
|
elif len(title) > 6:
|
|||
|
|
score -= 15
|
|||
|
|
|
|||
|
|
results.append({
|
|||
|
|
'filename': filename,
|
|||
|
|
'chapter_num': chapter_num,
|
|||
|
|
'title': title,
|
|||
|
|
'score': score
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return sorted(results, key=lambda x: int(x['chapter_num']))
|
|||
|
|
|
|||
|
|
def improve_all_titles():
|
|||
|
|
"""全面改进标题"""
|
|||
|
|
print("🌟 章节标题全面改进")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
current_titles = analyze_current_titles()
|
|||
|
|
|
|||
|
|
print(f"共发现 {len(current_titles)} 个章节")
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
# 显示当前标题质量
|
|||
|
|
poor_titles = []
|
|||
|
|
|
|||
|
|
for item in current_titles:
|
|||
|
|
grade = "A" if item['score'] >= 90 else "B" if item['score'] >= 70 else "C"
|
|||
|
|
|
|||
|
|
if grade == "C":
|
|||
|
|
print(f"❌ 第{item['chapter_num']}章: {item['title']} - 评分: {item['score']} (C级)")
|
|||
|
|
poor_titles.append(item)
|
|||
|
|
elif grade == "B":
|
|||
|
|
print(f"⚠ 第{item['chapter_num']}章: {item['title']} - 评分: {item['score']} (B级)")
|
|||
|
|
else:
|
|||
|
|
print(f"✅ 第{item['chapter_num']}章: {item['title']} - 评分: {item['score']} (A级)")
|
|||
|
|
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
if not poor_titles:
|
|||
|
|
print("✅ 所有标题质量良好,无需改进")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
print(f"共发现 {len(poor_titles)} 个需要改进的标题:")
|
|||
|
|
for item in poor_titles:
|
|||
|
|
current_title = item['title']
|
|||
|
|
improved_title = GOOD_TITLES.get(current_title, current_title)
|
|||
|
|
|
|||
|
|
if improved_title != current_title:
|
|||
|
|
print(f" {current_title} → {improved_title}")
|
|||
|
|
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
# 执行改进
|
|||
|
|
improved_count = 0
|
|||
|
|
|
|||
|
|
for item in poor_titles:
|
|||
|
|
filename = item['filename']
|
|||
|
|
current_title = item['title']
|
|||
|
|
chapter_num = item['chapter_num']
|
|||
|
|
|
|||
|
|
improved_title = GOOD_TITLES.get(current_title, current_title)
|
|||
|
|
|
|||
|
|
if improved_title == current_title:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
filepath = os.path.join(CHAPTERS_DIR, filename)
|
|||
|
|
|
|||
|
|
# 读取内容
|
|||
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 更新标题
|
|||
|
|
old_header = f"# 第{chapter_num}章 {current_title}"
|
|||
|
|
new_header = f"# 第{chapter_num}章 {improved_title}"
|
|||
|
|
|
|||
|
|
if old_header in content:
|
|||
|
|
content = content.replace(old_header, new_header, 1)
|
|||
|
|
|
|||
|
|
# 生成新文件名
|
|||
|
|
new_filename = f"ch{chapter_num}-第{chapter_num}章 {improved_title}.md"
|
|||
|
|
new_filepath = os.path.join(CHAPTERS_DIR, new_filename)
|
|||
|
|
|
|||
|
|
# 写入新文件
|
|||
|
|
with open(new_filepath, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
# 删除旧文件(如果文件名改变)
|
|||
|
|
if new_filename != filename:
|
|||
|
|
os.remove(filepath)
|
|||
|
|
|
|||
|
|
print(f"✅ 改进: 第{chapter_num}章 {current_title} → {improved_title}")
|
|||
|
|
improved_count += 1
|
|||
|
|
|
|||
|
|
if improved_count > 0:
|
|||
|
|
print(f"\n📊 改进完成! 共改进 {improved_count} 个标题")
|
|||
|
|
|
|||
|
|
# 显示改进前后的对比
|
|||
|
|
|
|||
|
|
print("\n📈 改进总结:")
|
|||
|
|
for item in poor_titles:
|
|||
|
|
if item['title'] in GOOD_TITLES and GOOD_TITLES[item['title']] != item['title']:
|
|||
|
|
print(f" 第{item['chapter_num']}章: {item['title']} → {GOOD_TITLES[item['title']]}")
|
|||
|
|
else:
|
|||
|
|
print("✅ 无需改进")
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
improve_all_titles()
|