Fetch datasets and validate the request #1
|
@ -1,5 +1,5 @@
|
||||||
from constants import datasets, url
|
from constants import datasets, url
|
||||||
from requests import get
|
from requests import get, codes
|
||||||
from json import dump
|
from json import dump
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,13 +10,22 @@ def save_json(data):
|
||||||
|
|
||||||
def request_dataset(url):
|
def request_dataset(url):
|
||||||
request = get(url)
|
request = get(url)
|
||||||
|
validate_request(request)
|
||||||
data = request.json()
|
data = request.json()
|
||||||
save_json(data)
|
save_json(data)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def validate_request(req):
|
||||||
url.format("deconfinement-pistes-cyclables-temporaires")
|
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()
|
|
||||||
|
|
Loading…
Reference in New Issue