graphPaname/app/request_datasets.py

32 lines
549 B
Python

from constants import datasets, url
from requests import get, codes
from json import dump
def save_json(data):
with open("cycling-paths.json", "w") as f:
dump(data, f, ensure_ascii=False)
def request_dataset(url):
request = get(url)
validate_request(request)
data = request.json()
save_json(data)
def validate_request(req):
try:
req.status_code == codes.ok()
except Exception:
print("Error")
def format_url():
for i in datasets:
link = url.format(datasets[i])
request_dataset(link)