diff --git a/.gitignore b/.gitignore index bfd8bda..1e0f511 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -app/__pycache__ +*/__pycache__ Design.org diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/constants.py b/app/constants.py index 9d13124..1e1f1d2 100644 --- a/app/constants.py +++ b/app/constants.py @@ -1,6 +1,11 @@ datasets = [ - "coronavirus-commercants-parisiens-livraison-a-domicile" - "deconfinement-pistes-cyclables-temporaires" - "deconfinement-paking-relais-doublement-des-places" + "coronavirus-commercants-parisiens-livraison-a-domicile", + "deconfinement-pistes-cyclables-temporaires", + "deconfinement-parking-relais-doublement-des-places", ] -url = "https://opendata.paris.fr/api/v2/catalog/datasets/{}/exports/json?rows=-1&pretty=false&timezone=UTC" +url = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1" +filenames = { + "coronavirus-commercants-parisiens-livraison-a-domicile": "home-delivery", + "deconfinement-pistes-cyclables-temporaires": "cycling-paths", + "deconfinement-parking-relais-doublement-des-places": "relay-parking", +} diff --git a/app/request_datasets.py b/app/request_datasets.py index 38e85d8..927cdab 100644 --- a/app/request_datasets.py +++ b/app/request_datasets.py @@ -1,22 +1,28 @@ from constants import datasets, url from requests import get -from json import dump +from constants import datasets, url, filenames +from requests import get, codes +from json import dump, dumps -def save_json(data): - with open("cycling-paths.json", "w") as f: +def save_json(data, filename): + data_dir = "../data/" + with open(data_dir + filename + ".json", "w") as f: dump(data, f, ensure_ascii=False) -def request_dataset(url): - request = get(url) - data = request.json() - save_json(data) +def request_dataset(url, filename): + response = get(url) + response.raise_for_status() + data = response.json() + save_json(data, filename) -def main(): - url.format("deconfinement-pistes-cyclables-temporaires") +def format_url(): + for set in datasets: + link = url.format(set) + request_dataset(link, filenames[set]) if __name__ == "__main__": - main() + format_url() diff --git a/data/.keep b/data/.keep new file mode 100644 index 0000000..e69de29