微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
48
scripts/ops/merge_session_summaries.py
Normal file
48
scripts/ops/merge_session_summaries.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""将 export/session_summaries/out/ 下的单条摘要 .txt 合并为 _summaries.json。
|
||||
|
||||
每个 .txt 文件名为 {short_id}.txt,内容为纯文本摘要。
|
||||
输出: export/session_summaries/_summaries.json
|
||||
格式: {"short_id": "摘要文本", ...}
|
||||
|
||||
用法:
|
||||
python -B scripts/ops/merge_session_summaries.py
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from _env_paths import ensure_repo_root
|
||||
|
||||
ensure_repo_root()
|
||||
|
||||
OUT_DIR = Path("export/session_summaries/out")
|
||||
DST = Path("export/session_summaries/_summaries.json")
|
||||
|
||||
|
||||
def main():
|
||||
if not OUT_DIR.exists():
|
||||
print(f"目录不存在: {OUT_DIR}")
|
||||
return
|
||||
|
||||
txt_files = sorted(OUT_DIR.glob("*.txt"))
|
||||
print(f"扫描到 {len(txt_files)} 个摘要文件")
|
||||
|
||||
result: dict[str, str] = {}
|
||||
skipped = 0
|
||||
for f in txt_files:
|
||||
short_id = f.stem
|
||||
content = f.read_text(encoding="utf-8").strip()
|
||||
if not content:
|
||||
skipped += 1
|
||||
continue
|
||||
result[short_id] = content
|
||||
|
||||
DST.write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"已写入 {DST}: {len(result)} 条摘要, 跳过 {skipped} 条空文件")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user