微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
31
_tmp_replace2.py
Normal file
31
_tmp_replace2.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""替换文档中商品域和库存域的内容"""
|
||||
|
||||
target = "docs/reports/dwd-table-structure-overview.md"
|
||||
source = "_tmp_goods_inventory_section.md"
|
||||
|
||||
with open(target, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
with open(source, "r", encoding="utf-8") as f:
|
||||
new_content = f.read()
|
||||
|
||||
# 找到 ## 7 和 ## 9 的行号
|
||||
start_idx = None
|
||||
end_idx = None
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith("## 7. 商品域"):
|
||||
start_idx = i
|
||||
elif line.startswith("## 9. 门店与员工维度"):
|
||||
end_idx = i
|
||||
break
|
||||
|
||||
if start_idx is None or end_idx is None:
|
||||
print(f"ERROR: start={start_idx}, end={end_idx}")
|
||||
else:
|
||||
# 确保新内容末尾有换行
|
||||
if not new_content.endswith("\n\n"):
|
||||
new_content = new_content.rstrip("\n") + "\n\n"
|
||||
result = lines[:start_idx] + [new_content] + lines[end_idx:]
|
||||
with open(target, "w", encoding="utf-8") as f:
|
||||
f.writelines(result)
|
||||
print(f"OK: 替换了行 {start_idx+1}~{end_idx} -> 新内容 {len(new_content)} 字符")
|
||||
Reference in New Issue
Block a user