graphPaname/app/request_datasets.py

29 lines
642 B
Python
Raw Normal View History

2020-05-21 18:50:00 +02:00
from constants import datasets, url
2020-05-21 18:45:51 +02:00
from requests import get
from constants import datasets, url, filenames
from requests import get, codes
from json import dump, dumps
2020-05-21 18:45:51 +02:00
def save_json(data, filename):
2020-05-27 20:45:21 +02:00
data_dir = "data/"
with open(data_dir + filename + ".json", "w") as f:
2020-05-21 18:45:51 +02:00
dump(data, f, ensure_ascii=False)
def request_dataset(url, filename):
response = get(url)
response.raise_for_status()
data = response.json()
save_json(data, filename)
2020-05-21 18:45:51 +02:00
def format_url():
for set in datasets:
link = url.format(set)
request_dataset(link, filenames[set])
2020-05-21 18:45:51 +02:00
if __name__ == "__main__":
format_url()