Created
March 22, 2018 09:20
-
-
Save trsqxyz/82226d37efab0f6ea2b87f01f71acfa4 to your computer and use it in GitHub Desktop.
hs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expantions = { | |
"CORE": "基本カード", | |
"EXPERT1": "クラシックカード", | |
"HOF": "栄誉の殿堂", | |
"NAXX": "ナクラーマスの呪い", | |
"GVG": "ゴブリンvsノーム", | |
"BRM": "ブラックロック・マウンテン", | |
"TGT": "グランド・トーナメント", | |
"LOE": "探検同盟", | |
"OG": "旧神のささやき", | |
"KARA": "ワン・ナイト・イン・カラザン", | |
"GANGS": "仁義なきガジェッツァン", | |
"UNGORO": "大魔境ウンゴロ", | |
"ICECROWN": "凍てつく玉座の騎士団", | |
"LOOTAPALOOZA": "コボルトと秘宝の迷宮", | |
} | |
standard = ["CORE", "EXPERT1"] | |
prestandard = ["NAXX", "GVG", "BRM", "TGT", "LOE"] | |
year_of_kraken = ["OG", "KARA", "GANGS"] | |
year_of_mammoth = ["UNGORO", "ICECROWN", "LOOTAPALOOZA"] | |
year_of_raven = [] | |
standard = standard + year_of_mammoth + year_of_raven |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import os | |
import json | |
import requests | |
import csv | |
import codecs | |
from Expantions import expantions, standard | |
db_url = "https://api.hearthstonejson.com/v1/23576/jaJP/cards.collectible.json" | |
db_path = "./db.json" | |
if os.path.exists(db_path): | |
with codecs.open(db_path, "r", "utf-8") as f: | |
db = json.loads(f.read()) | |
else: | |
response = requests.get(db_url) | |
if response.status_code == 200: | |
with codecs.open(db_path, "w", "utf-8") as f: | |
f.write(response.text) | |
db = response.json() | |
else: | |
raise RuntimeError("Couldn't download cards database: %s" | |
% response.text) | |
carddata = [ | |
[ | |
"セット", | |
"スタンダード", | |
"クラス", | |
"レアリティ", | |
"コスト", | |
"偶数奇数", | |
"カード名", | |
"テキスト", | |
"攻撃力", | |
"体力", | |
"フレーバーテキスト", | |
"アーティスト", | |
], | |
] | |
for data in db: | |
card = [] | |
try: | |
for k in ("set", "cardClass", "rarity", "cost", "name", "text", "attack", "health", "flavor", "artist",): | |
try: | |
card.append(data[k]) | |
if k == "cost": | |
if data[k]%2 == 0: | |
card.append("偶数") | |
else: | |
card.append("奇数") | |
if k == "set": | |
if data[k] in standard: | |
card.append("スタンダード") | |
else: | |
card.append("") | |
card[-2] = expantions[data[k]] | |
else: | |
pass | |
except (KeyError): | |
card.append("") | |
else: | |
carddata.append(card) | |
except: | |
pass | |
with codecs.open('hs.csv', 'w', "utf-8") as f: | |
writer = csv.writer(f, lineterminator='\n') | |
writer.writerows(carddata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment