Files
note_sync/大模型/deepseek/_scripts/sync_plan_paths.py
T

41 lines
1.1 KiB
Python

"""Sync plan.json md_path with the actual note filenames on disk.
The notes were renamed with an `_abstract` suffix to avoid page-name clashes
with the same-named PDFs in SilverBullet. This rewrites plan.json accordingly.
Usage: python sync_plan_paths.py <plan.json> <base_dir>
"""
import json
import os
import sys
plan_path, base = sys.argv[1], sys.argv[2]
plan = json.load(open(plan_path, encoding='utf-8'))
changed = 0
missing = []
for p in plan:
d = p['dir']
stem = p['stem']
candidates = [
os.path.join(d, stem + '.md'),
os.path.join(d, stem + '_abstract.md'),
]
found = None
for c in candidates:
if os.path.exists(os.path.join(base, c)):
found = c
break
if not found:
missing.append((p['id'], stem))
continue
if p['md_path'] != found:
p['md_path'] = found
changed += 1
json.dump(plan, open(plan_path, 'w', encoding='utf-8'), ensure_ascii=False, indent=1)
print('md_path 已更新:', changed, '/', len(plan))
if missing:
print('未找到对应 md 的论文:')
for m in missing:
print(' !', m)