fix_season_random.py 891 B

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