2020-05-21 18:50:00 +02:00
|
|
|
from constants import datasets, url
|
2020-05-21 19:22:42 +02:00
|
|
|
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)
|
2020-05-21 19:22:42 +02:00
|
|
|
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
|
|
|
|
2020-05-21 19:22:42 +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
|
|
|
|
|
|
|
|
|
|
|
|