Browse Source

fetching happily ever after

master
Dorian Bourgeoisat 7 months ago
parent
commit
4432188211
  1. 3
      .gitignore
  2. 42
      database-update.py

3
.gitignore

@ -1,2 +1,3 @@
/target
cards.db
cards.db
all_cards*

42
database-update.py

@ -0,0 +1,42 @@
#!/bin/python
# import urllib library
from urllib.request import urlopen
# import json
import json
# store the URL in url as
# parameter for urlopen
url = "https://api.scryfall.com/bulk-data"
# store the response of URL
response = urlopen(url)
# storing the JSON response
# from url in data
data_json = json.loads(response.read())
bulk_files = [];
# print the json response
for file in data_json["data"]:
if (file["type"]=="all_cards"):
print("{} <- Will download this database".format(file["name"]))
bulk_files.append(file)
else:
print("{}".format(file["name"]))
CHUNK = 256 * 1024
for file in bulk_files:
uri = file["download_uri"]
filename = file["type"]+"_"+file["id"]+".json"
rep = urlopen(uri)
with open(filename, 'wb') as f:
while True:
chunk = rep.read(CHUNK)
if not chunk:
break
f.write(chunk)
Loading…
Cancel
Save