proc.py 903 B

123456789101112131415161718192021222324252627282930
  1. import json
  2. import os
  3. j = None
  4. with open('cards.json') as fp:
  5. j = json.load(fp)
  6. def list_files(directory):
  7. files = os.listdir(directory)
  8. return [file for file in files if not os.path.isdir(os.path.join(directory, file))]
  9. fin_set = set(list_files('./cardtext-fin'))
  10. for k in j:
  11. v = j[k]
  12. if v['id'] == 0:
  13. continue
  14. if str(v['id']) + '.txt' in fin_set:
  15. continue
  16. s = ''
  17. s += v['cn_name'] + '\n'
  18. if "set_ext" in v:
  19. s += '(系列:' + v['set_ext'] + ')\n'
  20. types = v['text']['types']
  21. types = types.replace('☆', '阶级').replace('★', '等级')
  22. s += types + '\n'
  23. if 'pdesc' in v['text'] and len(v['text']['pdesc']) > 0:
  24. s += '---\n' + v['text']['pdesc'].replace('\r', '').strip() + '\n---\n'
  25. s += v['text']['desc'].replace('\r', '')
  26. with open('cardtext/' + str(v['id']) + '.txt', 'w') as fp:
  27. fp.write(s)