graphPaname/app/request_datasets.py

32 lines
549 B
Python
Raw Normal View History

2020-05-21 18:50:00 +02:00
from constants import datasets, url
from requests import get, codes
2020-05-21 18:45:51 +02:00
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)
2020-05-21 18:50:00 +02:00
data = request.json()
save_json(data)
2020-05-21 18:45:51 +02:00
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)
2020-05-21 18:45:51 +02:00