Files
group_fqcd_jr/客服agent/_build/_normalize_ids.py
T

31 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""把正文里的 h2/h3 id 规范化为「无空格、无中点」的形式(项目既有惯例)。"""
from pathlib import Path
TARGETS = [
Path(r"D:\桌面\金融\_body_plan.html"),
Path(r"D:\桌面\金融\_body_requirements.html"),
Path(r"D:\桌面\金融\_body_kb.html"),
]
MAP = {
'id="3.2-批次 A · 冻结与准备"': 'id="3.2-批次A-冻结与准备"',
'id="3.3-批次 B 至 F 摘要"': 'id="3.3-批次B至F摘要"',
'id="3.4-批次 G · 访客与鉴权"': 'id="3.4-批次G-访客与鉴权"',
'id="4.1-组 1 · 六文件八处"': 'id="4.1-组1-六文件八处"',
'id="4.2-组 2 · 访客与鉴权四文件"': 'id="4.2-组2-访客与鉴权四文件"',
}
log = []
for p in TARGETS:
if not p.exists():
log.append(f"[SKIP] {p.name} 不存在")
continue
t = p.read_text(encoding="utf-8")
changed = 0
for old, new in MAP.items():
if old in t:
t = t.replace(old, new)
changed += 1
p.write_text(t, encoding="utf-8")
log.append(f"[OK] {p.name} 规范化 {changed} 处 id")
Path(r"D:\桌面\金融\_norm.txt").write_text("\n".join(log), encoding="utf-8")