cn-genbanlist.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import json
  2. import urllib.request
  3. cardId = dict()
  4. cards = None
  5. with open('cards.json', 'r') as fp:
  6. cards = json.load(fp)
  7. result = dict()
  8. result['ban'] = []
  9. result['limit'] = []
  10. result['semiLimit'] = []
  11. for k in cards:
  12. cardId[k] = cards[k]['id']
  13. if 'sc_name' not in cards[k]:
  14. result['ban'].append(str(cardId[k]))
  15. def transform_card_data(input_json):
  16. output_data = {"regulation": {}}
  17. for item in input_json["list"]:
  18. for card in item["list"]:
  19. card_no = card["cardNo"]
  20. forbidden_type = card["type"]
  21. if "禁止卡" == forbidden_type:
  22. output_data["regulation"][card_no] = 0
  23. elif "限制卡" == forbidden_type:
  24. output_data["regulation"][card_no] = 1
  25. elif "准限制卡" == forbidden_type:
  26. output_data["regulation"][card_no] = 2
  27. return output_data
  28. url = "https://yxwdbapi.windoent.com/forbiddenCard/forbiddencard/cachelist?groupId=1"
  29. source_data = ""
  30. with urllib.request.urlopen(url) as response:
  31. data = response.read().decode('utf-8')
  32. source_data = json.loads(data)
  33. with open('banlist-cn.json', 'w') as fp:
  34. json.dump(transform_card_data(source_data), fp)
  35. banlist = None
  36. with open('banlist-cn.json', 'r') as fp:
  37. banlist = json.load(fp)
  38. regulation = banlist['regulation']
  39. for cid in regulation:
  40. sid = str(cardId[cid])
  41. if regulation[cid] == 0:
  42. result['ban'].append(sid)
  43. if regulation[cid] == 1:
  44. result['limit'].append(sid)
  45. if regulation[cid] == 2:
  46. result['semiLimit'].append(sid)
  47. result['ban'] = list(set(result['ban']))
  48. print(json.dumps(result, indent=4))