72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
"""
|
|||
|
|
Settings.php AI 功能重构脚本
|
|||
|
|
移除旧的 AI 设置,插入新的统一 AI 功能部分
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 读取文件
|
|||
|
|
with open('settings.php', 'r', encoding='utf-8') as f:
|
|||
|
|
lines = f.readlines()
|
|||
|
|
|
|||
|
|
# 读取新的 AI 部分
|
|||
|
|
with open('tmp/complete-ai-section.php', 'r', encoding='utf-8') as f:
|
|||
|
|
new_ai_section = f.read()
|
|||
|
|
|
|||
|
|
# 读取评论审核的其他设置(保留非 AI 部分)
|
|||
|
|
with open('tmp/comment-settings-other.txt', 'r', encoding='utf-8') as f:
|
|||
|
|
comment_other_settings = f.read()
|
|||
|
|
|
|||
|
|
# 步骤 1: 在第 1985 行之前插入新的 AI 功能部分
|
|||
|
|
# 步骤 2: 移除第 1987-2599 行(旧的 AI 摘要设置)
|
|||
|
|
# 步骤 3: 在评论设置中移除 AI 垃圾评论识别子分类,添加到新的 AI 功能部分
|
|||
|
|
|
|||
|
|
# 找到插入位置(文章功能之前)
|
|||
|
|
insert_pos = None
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
if '<!-- ========== 12. 文章功能 ==========' in line:
|
|||
|
|
insert_pos = i
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
if insert_pos is None:
|
|||
|
|
print("错误:找不到文章功能部分")
|
|||
|
|
exit(1)
|
|||
|
|
|
|||
|
|
# 找到需要移除的旧 AI 摘要设置的结束位置
|
|||
|
|
remove_end = None
|
|||
|
|
for i in range(insert_pos, len(lines)):
|
|||
|
|
if 'subsection-footnote' in lines[i] and '脚注引用' in lines[i]:
|
|||
|
|
remove_end = i
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
if remove_end is None:
|
|||
|
|
print("错误:找不到脚注引用部分")
|
|||
|
|
exit(1)
|
|||
|
|
|
|||
|
|
print(f"将在第 {insert_pos + 1} 行插入新的 AI 功能部分")
|
|||
|
|
print(f"将移除第 {insert_pos + 3} 到 {remove_end} 行的旧 AI 摘要设置")
|
|||
|
|
|
|||
|
|
# 构建新文件
|
|||
|
|
new_lines = []
|
|||
|
|
|
|||
|
|
# 保留插入位置之前的内容
|
|||
|
|
new_lines.extend(lines[:insert_pos])
|
|||
|
|
|
|||
|
|
# 插入新的 AI 功能部分
|
|||
|
|
new_lines.append(new_ai_section)
|
|||
|
|
new_lines.append('\n')
|
|||
|
|
|
|||
|
|
# 跳过旧的 AI 摘要设置,保留文章功能标题和之后的内容
|
|||
|
|
new_lines.append(lines[insert_pos]) # 文章功能标题
|
|||
|
|
new_lines.append(lines[insert_pos + 1]) # <tr><th class="subtitle">
|
|||
|
|
|
|||
|
|
# 保留脚注引用及之后的内容
|
|||
|
|
new_lines.extend(lines[remove_end:])
|
|||
|
|
|
|||
|
|
# 写入新文件
|
|||
|
|
with open('settings.php', 'w', encoding='utf-8') as f:
|
|||
|
|
f.writelines(new_lines)
|
|||
|
|
|
|||
|
|
print("✓ 成功插入新的 AI 功能部分")
|
|||
|
|
print("✓ 成功移除旧的 AI 摘要设置")
|
|||
|
|
print(f"✓ 文件行数变化:{len(lines)} → {len(new_lines)}")
|