Generates set.json files from Scryfall
I should have done this in the first place instead of figuring out how to use MTGJSON files. Scryfall structures its data a bit differently and notably includes a list of keywords for each card. Having these set.json files enables easier analysis of the keyword content of each set.
This commit is contained in:
parent
40f12289a2
commit
9dd4186e1c
2 changed files with 159 additions and 0 deletions
40
scryfall_requests.py
Normal file
40
scryfall_requests.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
# Requests card objects from each set from Scryfall.com
|
||||||
|
# Takes a few seconds and creates a ~1 MB json file per set
|
||||||
|
# Reads set codes on separate lines in set_codes.txt
|
||||||
|
|
||||||
|
def request_set(code):
|
||||||
|
time.sleep(0.1) # Scryfall asks for 50-100 ms delay between requests
|
||||||
|
# Scryfall query is "set:code in:booster"
|
||||||
|
url = f'https://api.scryfall.com/cards/search?q=set%3A{code}+in%3Dbooster'
|
||||||
|
print(f'Requesting {code}')
|
||||||
|
response = requests.get(url)
|
||||||
|
d = response.json()
|
||||||
|
cards = []
|
||||||
|
cards += d['data']
|
||||||
|
while d['has_more']:
|
||||||
|
time.sleep(0.1)
|
||||||
|
print(f'Requesting {code} next page')
|
||||||
|
response = requests.get(d['next_page'])
|
||||||
|
d = response.json()
|
||||||
|
cards += d['data']
|
||||||
|
output_cards = json.dumps(cards)
|
||||||
|
if code == 'CON':
|
||||||
|
code = 'CON_'
|
||||||
|
f = open(f'scryfall/sets/{code}.json', 'w+')
|
||||||
|
f.write(output_cards)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
sets = []
|
||||||
|
set_file = open('set_codes.txt')
|
||||||
|
for line in set_file:
|
||||||
|
sets += [line.strip()]
|
||||||
|
set_file.close()
|
||||||
|
|
||||||
|
for code in sets:
|
||||||
|
request_set(code)
|
||||||
119
set_codes.csv
Normal file
119
set_codes.csv
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
2ED
|
||||||
|
3ED
|
||||||
|
4ED
|
||||||
|
5ED
|
||||||
|
6ED
|
||||||
|
7ED
|
||||||
|
8ED
|
||||||
|
9ED
|
||||||
|
10E
|
||||||
|
M10
|
||||||
|
M11
|
||||||
|
M12
|
||||||
|
M13
|
||||||
|
M14
|
||||||
|
M15
|
||||||
|
ORI
|
||||||
|
M19
|
||||||
|
M20
|
||||||
|
M21
|
||||||
|
POR
|
||||||
|
P02
|
||||||
|
PTK
|
||||||
|
S99
|
||||||
|
ARN
|
||||||
|
ATQ
|
||||||
|
LEG
|
||||||
|
DRK
|
||||||
|
FEM
|
||||||
|
HML
|
||||||
|
ICE
|
||||||
|
ALL
|
||||||
|
MIR
|
||||||
|
VIS
|
||||||
|
WTH
|
||||||
|
TMP
|
||||||
|
STH
|
||||||
|
EXO
|
||||||
|
USG
|
||||||
|
ULG
|
||||||
|
UDS
|
||||||
|
MMQ
|
||||||
|
NEM
|
||||||
|
PCY
|
||||||
|
INV
|
||||||
|
PLS
|
||||||
|
APC
|
||||||
|
ODY
|
||||||
|
TOR
|
||||||
|
JUD
|
||||||
|
ONS
|
||||||
|
LGN
|
||||||
|
SCG
|
||||||
|
MRD
|
||||||
|
DST
|
||||||
|
5DN
|
||||||
|
CHK
|
||||||
|
BOK
|
||||||
|
SOK
|
||||||
|
RAV
|
||||||
|
GPT
|
||||||
|
DIS
|
||||||
|
CSP
|
||||||
|
TSP
|
||||||
|
PLC
|
||||||
|
FUT
|
||||||
|
LRW
|
||||||
|
MOR
|
||||||
|
SHM
|
||||||
|
EVE
|
||||||
|
ALA
|
||||||
|
CON_
|
||||||
|
ARB
|
||||||
|
ZEN
|
||||||
|
WWK
|
||||||
|
ROE
|
||||||
|
SOM
|
||||||
|
MBS
|
||||||
|
NPH
|
||||||
|
ISD
|
||||||
|
DKA
|
||||||
|
AVR
|
||||||
|
RTR
|
||||||
|
GTC
|
||||||
|
DGM
|
||||||
|
THS
|
||||||
|
BNG
|
||||||
|
JOU
|
||||||
|
KTK
|
||||||
|
FRF
|
||||||
|
DTK
|
||||||
|
BFZ
|
||||||
|
OGW
|
||||||
|
SOI
|
||||||
|
EMN
|
||||||
|
KLD
|
||||||
|
AER
|
||||||
|
AKH
|
||||||
|
HOU
|
||||||
|
XLN
|
||||||
|
RIX
|
||||||
|
DOM
|
||||||
|
GRN
|
||||||
|
RNA
|
||||||
|
WAR
|
||||||
|
ELD
|
||||||
|
THB
|
||||||
|
IKO
|
||||||
|
ZNR
|
||||||
|
MMA
|
||||||
|
MM2
|
||||||
|
EMA
|
||||||
|
MM3
|
||||||
|
IMA
|
||||||
|
A25
|
||||||
|
UMA
|
||||||
|
2XM
|
||||||
|
MH1
|
||||||
|
CMR
|
||||||
|
JMP
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue