Fetch datasets and validate the request #1
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue