| 123456789101112131415161718192021222324 |
- import json
- with open('backend/data/templates.json', 'r', encoding='utf-8') as f:
- data = json.load(f)
- # 找出所有季节模板
- season_templates = [t for t in data if 'season' in t.get('template_type', '')]
- print(f'找到 {len(season_templates)} 个季节模板:')
- for t in season_templates:
- has_first = '| first' in t.get('template_body', '')
- has_random = '| random' in t.get('template_body', '')
- print(f" {t['id']}: {t['template_type']} (first={has_first}, random={has_random})")
-
- # 替换 first 为 random
- if has_first:
- t['template_body'] = t['template_body'].replace('| first}}', '| random}}')
- print(f" ✓ 已替换 | first 为 | random")
- # 保存
- with open('backend/data/templates.json', 'w', encoding='utf-8') as f:
- json.dump(data, f, ensure_ascii=False, indent=2)
- print(f'\n完成!已保存修改')
|