From 7044dda659f20a227edf10c84dbf4f5df3e1b795 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 10 Jun 2020 21:49:58 +0200 Subject: [PATCH] Remove FILENAMES constant --- app/constants.py | 56 +++++++++++++++++++---------------------- app/preprocessing.py | 4 +-- app/request_datasets.py | 5 ++-- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/app/constants.py b/app/constants.py index 9527b12..1675fc2 100644 --- a/app/constants.py +++ b/app/constants.py @@ -4,42 +4,38 @@ DATASETS = [ "deconfinement-parking-relais-doublement-des-places", ] 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", -} +TEST_URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset=deconfinement-pistes-cyclables-temporaires&rows=-1" FILES = { - "cycling-paths": "data/cycling-paths.json", - "relay-parking": "data/relay-parking.json", - "home-delivery": "data/home-delivery.json", + "deconfinement-pistes-cyclables-temporaires": "data/cycling-paths.json", + "deconfinement-parking-relais-doublement-des-places": "data/relay-parking.json", + "coronavirus-commercants-parisiens-livraison-a-domicile": "data/home-delivery.json", } COLUMNS = { - "cycling-paths": [ - ["fields", "geo_shape", "coordinates"], - "statut", + "deconfinement-pistes-cyclables-temporaires": [ + "fields.geo_shape.coordinates", + "fields.statut", "record_timestamp", - "complement", + "fields.complement", ], - "relay-parking": [ - "societe", - "nb_places_dispositif_environ", - "parcs", - "geo_shape", - "cp", - "ville", - "adresse", + "deconfinement-parking-relais-doublement-des-places": [ + "fields.societe", + "fields.nb_places_dispositif_environ", + "fields.parcs", + "fields.geo_shape.coordinates", + "fields.cp", + "fields.ville", + "fields.adresse", ], - "home-delivery": [ - "geo_shape", - "adresse", - "code_postal", - "nom_du_commerce", - "type_du_commerce", - "site_internet", + "coronavirus-commercants-parisiens-livraison-a-domicile": [ + "fields.geo_shape.coordinates", + "fields.adresse", + "fields.code_postal", + "fields.nom_du_commerce", + "fields.type_de_commerce", + "fields.site_internet", "record_timestamp", - "precisions", - "telephone", - "mail", + "fields.precisions", + "fields.telephone", + "fields.mail", ], } diff --git a/app/preprocessing.py b/app/preprocessing.py index c276843..3dcc574 100644 --- a/app/preprocessing.py +++ b/app/preprocessing.py @@ -1,6 +1,6 @@ from json import load -from pandas import json_normalize, DataFrame, set_option -from constants import FILES, COLUMNS +from pandas import json_normalize, DataFrame +from .constants import FILES, COLUMNS def open_json(dataset) -> dict: diff --git a/app/request_datasets.py b/app/request_datasets.py index 2a4eb2e..0e1534f 100644 --- a/app/request_datasets.py +++ b/app/request_datasets.py @@ -1,6 +1,6 @@ from json import dump from requests import get -from constants import FILENAMES, URL +from .constants import FILES, URL def format_url(dataset) -> str: @@ -15,8 +15,7 @@ def save_json(data, dataset): """ Dumps the data into a JSON file """ - data_dir = "data/" - with open(data_dir + FILENAMES[dataset] + ".json", "w") as f: + with open(FILES[dataset], "w") as f: dump(data, f, ensure_ascii=False)