build-card-info.py 811 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import json
  3. j = None
  4. with open('cards.json') as fp:
  5. j = json.load(fp)
  6. outData = dict()
  7. def convert(card):
  8. newCard = dict()
  9. newCard['names'] = []
  10. for namek in ['cn_name', 'sc_name', 'md_name', 'nwbbs_n', \
  11. 'cnocg_n', 'jp_ruby', 'jp_name', 'en_name']:
  12. if namek in card and len(card[namek]) > 0:
  13. newCard['names'].append(card[namek])
  14. newCard['isExtra'] = False
  15. for t in ['超量', '链接', '同调', '融合']:
  16. if t in card['text']['types']:
  17. newCard['isExtra'] = True
  18. newCard['cid'] = card['cid']
  19. return newCard
  20. for k in j:
  21. outData[j[k]['id']] = convert(j[k])
  22. outStr = 'export const cardDb = ' + json.dumps(outData) + ';'
  23. with open('../src/data/cardDb.js', 'w') as fp:
  24. fp.write(outStr)