aboutsummaryrefslogtreecommitdiff
path: root/data/cn-genbanlist.py
diff options
context:
space:
mode:
Diffstat (limited to 'data/cn-genbanlist.py')
-rw-r--r--data/cn-genbanlist.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/data/cn-genbanlist.py b/data/cn-genbanlist.py
index c80d7f0..6167990 100644
--- a/data/cn-genbanlist.py
+++ b/data/cn-genbanlist.py
@@ -1,4 +1,5 @@
import json
+import urllib.request
cardId = dict()
cards = None
@@ -15,6 +16,31 @@ for k in cards:
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)
@@ -29,5 +55,6 @@ for cid in regulation:
if regulation[cid] == 2:
result['semiLimit'].append(sid)
result['ban'] = list(set(result['ban']))
-print(json.dumps(result, indent=4))
+print(json.dumps(result, indent=4))
+