diff options
| author | Mistivia <i@mistivia.com> | 2025-04-16 18:53:55 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-04-16 18:54:06 +0800 |
| commit | df0e994d8e48e7e4b8e33fa70a373287634ea0e3 (patch) | |
| tree | c6fb0bed483a8298e17c640bc1a594fc768c92d1 /data/fetch-tcg-banlist.py | |
| parent | 870a4aac0d18458dbccabe36786f09e2e7f15c7c (diff) | |
update data script
Diffstat (limited to 'data/fetch-tcg-banlist.py')
| -rw-r--r-- | data/fetch-tcg-banlist.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/data/fetch-tcg-banlist.py b/data/fetch-tcg-banlist.py new file mode 100644 index 0000000..197b9c3 --- /dev/null +++ b/data/fetch-tcg-banlist.py @@ -0,0 +1,35 @@ +import json +import urllib.request +import re + +url = "https://www.db.yugioh-card.com/yugiohdb/forbidden_limited.action?request_locale=en" + +source_data = "" +with urllib.request.urlopen(url) as response: + data = response.read().decode('utf-8') + +current_status = -1 + +output_data = {"regulation": {}} + +for line in data.split('\n'): + if '</div><!-- #list_semi_limited .list_set -->' in line: + current_status = -1 + if '<div id="list_semi_limited" class="list_set">' in line: + current_status = 2 + if '<div id="list_forbidden" class="list_set">' in line: + current_status = 0 + if '<div id="list_limited" class="list_set">' in line: + current_status = 1 + + pattern = r'<input type="hidden" class="link_value" value="/yugiohdb/card_search\.action\?ope=\d+&cid=(\d+)">' + match = re.search(pattern, line) + if match and current_status >= 0: + cid = match.group(1) + output_data["regulation"][cid] = current_status + + +with open('banlist-tcg.json', 'w') as fp: + json.dump(output_data, fp) + + |
