aboutsummaryrefslogtreecommitdiff
path: root/data/cn-genbanlist.py
blob: 61679901f07d1590f064ffc9e8a5e5707c442867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
import urllib.request

cardId = dict()
cards = None
with open('cards.json', 'r') as fp:
    cards = json.load(fp)

result = dict()
result['ban'] = []
result['limit'] = []
result['semiLimit'] = []

for k in cards:
    cardId[k] = cards[k]['id']
    if 'sc_name' not in cards[k]:
        result['ban'].append(str(cardId[k]))


def transform_card_data(input_json):
   output_data = {"regulation": {}}
   for item in input_json["list"]:
       for card in item["list"]:
           card_no = card["cardNo"]
           forbidden_type = card["type"]
           if "禁止卡" == forbidden_type:
               output_data["regulation"][card_no] = 0
           elif "限制卡" == forbidden_type:
               output_data["regulation"][card_no] = 1
           elif "准限制卡" == forbidden_type:
               output_data["regulation"][card_no] = 2
   return output_data

url = "https://yxwdbapi.windoent.com/forbiddenCard/forbiddencard/cachelist?groupId=1"

source_data = ""
with urllib.request.urlopen(url) as response:
    data = response.read().decode('utf-8')
    source_data = json.loads(data)

with open('banlist-cn.json', 'w') as fp:
    json.dump(transform_card_data(source_data), fp)

banlist = None
with open('banlist-cn.json', 'r') as fp:
    banlist = json.load(fp)

regulation = banlist['regulation']
for cid in regulation:
    sid = str(cardId[cid])
    if regulation[cid] == 0:
        result['ban'].append(sid)
    if regulation[cid] == 1:
        result['limit'].append(sid)
    if regulation[cid] == 2:
        result['semiLimit'].append(sid)
result['ban'] = list(set(result['ban']))
    
print(json.dumps(result, indent=4))