Added validate_request(req) and format_url()

This commit is contained in:
basset 2020-05-21 19:22:42 +02:00
parent 626fc4bfd8
commit 8c7f60aa50
1 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,5 @@
from constants import datasets, url
from requests import get
from requests import get, codes
from json import dump
@ -10,13 +10,22 @@ def save_json(data):
def request_dataset(url):
request = get(url)
validate_request(request)
data = request.json()
save_json(data)
def main():
url.format("deconfinement-pistes-cyclables-temporaires")
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)
if __name__ == "__main__":
main()