Files
spider-ctext/佩文韵府/fix_volume.py
2026-03-22 16:18:35 +08:00

29 lines
745 B
Python

import json
print("Loading peiwenyunfu.json...")
with open('peiwenyunfu.json', 'r', encoding='utf-8') as f:
data = json.load(f)
current_vol = ""
fixed_count = 0
for rhyme, r_data in data.items():
if rhyme in ['metadata', 'preface']:
continue
vol = r_data.get("", "")
if vol.strip():
# Update current valid volume
current_vol = vol.strip()
else:
# If volume is empty, use the current_vol
if current_vol:
r_data[""] = current_vol
fixed_count += 1
print(f"Fixed {fixed_count} missing volumes.")
with open('peiwenyunfu.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
print("Saved to peiwenyunfu.json!")