From 8c7f60aa50b6fff83b8ec890c8c9d9d559be876c Mon Sep 17 00:00:00 2001 From: basset Date: Thu, 21 May 2020 19:22:42 +0200 Subject: [PATCH] Added validate_request(req) and format_url() --- app/request_datasets.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/request_datasets.py b/app/request_datasets.py index 38e85d8..c5cbb3b 100644 --- a/app/request_datasets.py +++ b/app/request_datasets.py @@ -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()