From 8897764b9cc5d50bc1e7961645da9910de78e67c Mon Sep 17 00:00:00 2001 From: SebF Date: Sun, 3 Oct 2021 18:10:19 +0200 Subject: [PATCH] =?UTF-8?q?extraction=20des=20requ=C3=AAtes=20dans=20une?= =?UTF-8?q?=20classe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- osm_vc63/requetes.py | 143 ++++++++++++++++++++++ recup_donnees_OSM_Overpass.py | 216 +--------------------------------- 2 files changed, 147 insertions(+), 212 deletions(-) create mode 100644 osm_vc63/requetes.py diff --git a/osm_vc63/requetes.py b/osm_vc63/requetes.py new file mode 100644 index 0000000..a8b9a9c --- /dev/null +++ b/osm_vc63/requetes.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 + + +class requete: + nom: str + critere: str + champs: dict + + def __init__(self, nom, critere, champs): + self.nom = nom + self.critere = critere + self.champs = champs + + +reqs = [] +champs_stationnement = { + "amenity": {"export_json": "Non", "FR": "aménagement"}, + "capacity": {"export_json": "Oui", "FR": "nombre d'emplacements"}, + "access": {"export_json": "Oui", "FR": "accès"}, + "bicycle_parking": {"export_json": "Oui", "FR": "type"}, + "covered": {"export_json": "Oui", "FR": "couvert"}, + "operator": {"export_json": "Oui", "FR": "opérateur"}, + "operator:type": {"export_json": "Oui", "FR": "type d'opérateur"}, + "fee": {"export_json": "Oui", "FR": "frais"}, + "check_date:capacity": {"export_json": "Non", "FR": "date_vérification"}, + "source": {"export_json": "Non", "FR": "source"}, +} +champs_poi = { + "name": {"export_json": "Oui", "FR": ""}, + "description": {"export_json": "Oui", "FR": ""}, + "website": {"export_json": "Oui", "FR": ""}, + "addr:housenumber": {"export_json": "Oui", "FR": ""}, + "addr:street": {"export_json": "Oui", "FR": ""}, + "addr:postcode": {"export_json": "Oui", "FR": ""}, + "addr:city": {"export_json": "Oui", "FR": ""}, + "contact:email": {"export_json": "Oui", "FR": "email"}, + "contact:twitter": {"export_json": "Oui", "FR": "Twitter"}, + "contact:facebook": {"export_json": "Oui", "FR": "Facebook"}, + "contact:phone": {"export_json": "Oui", "FR": "Téléphone"}, + "network": {"export_json": "Oui", "FR": "Réseau"}, + "office": {"export_json": "Oui", "FR": "Bureau"}, + "opening_hours": {"export_json": "Oui", "FR": "Horaires"}, +} +# fields api_adresse (issus du géocodage inversé) +champs_adresse = { + "api_adresse:geometry:coordinates:lon": { + "export_json": "Non", + "FR": "lon_adresse_etalab", + }, + "api_adresse:geometry:coordinates:lat": { + "export_json": "Non", + "FR": "lat_adresse_etalab", + }, + "api_adresse:properties:label": {"export_json": "Non", "FR": "adresse_etalab"}, + "api_adresse:properties:score": {"export_json": "Non", "FR": "score_etalab"}, + "api_adresse:properties:housenumber": {"export_json": "Non", "FR": "numero_etalab"}, + "api_adresse:properties:type": {"export_json": "Non", "FR": "type_etalab"}, + "api_adresse:properties:name": { + "export_json": "Non", + "FR": "numero_et_voie_etalab", + }, + "api_adresse:properties:postcode": { + "export_json": "Non", + "FR": "code_postal_etalab", + }, + "api_adresse:properties:citycode": { + "export_json": "Non", + "FR": "code_INSEE_etalab", + }, + "api_adresse:properties:city": {"export_json": "Non", "FR": "ville_etalab"}, + "api_adresse:properties:street": {"export_json": "Non", "FR": "rue_etalab"}, +} + +reqs.append( + requete( + "stationnements_velos_publics", + r'nwr["amenity"="bicycle_parking"](area:aire_de_recherche); - nwr["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers)"](area:aire_de_recherche);', + dict(champs_stationnement, **champs_adresse), + ) +) + +reqs.append( + requete( + "stationnements_velos_non_publics", + r'nwr["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers)"](area:aire_de_recherche);', + dict(champs_stationnement, **champs_adresse), + ) +) + +champ_local = {"service:bicycle:diy": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "ateliers_autoreparation", + r'nwr["service:bicycle:diy"="yes"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + +champ_local = {"association": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "associations_velo", + r'nwr["association"="bicycle"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + +champ_local = {"craft": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "fabriquants_velo", + r'nwr["craft"="bicycle"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + +champ_local = {"shop": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "vendeurs_velo", + r'nwr["shop"="bicycle"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + +champ_local = {"amenity": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "velos_libre_service", + r'nwr["amenity"="bicycle_rental"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + +champ_local = {"service:bicycle:rental": {"export_json": "Non", "FR": ""}} +reqs.append( + requete( + "location_velo", + r'nwr["service:bicycle:rental"="yes"](area:aire_de_recherche);', + dict(champ_local, **champs_poi, **champs_adresse), + ) +) + diff --git a/recup_donnees_OSM_Overpass.py b/recup_donnees_OSM_Overpass.py index 97d62cb..7fc310b 100644 --- a/recup_donnees_OSM_Overpass.py +++ b/recup_donnees_OSM_Overpass.py @@ -22,6 +22,7 @@ from pyexcel_ods3 import save_data from collections import OrderedDict import os from osm_vc63 import errors +from osm_vc63 import requetes overpass_url="http://overpass-api.de/api/interpreter" geo_api_url = "https://api-adresse.data.gouv.fr" @@ -44,215 +45,6 @@ aire_de_recherche = str(3600000000+110866) -# fields api_adresse (issus du géocodage inversé) -api_adresse_fields = { "api_adresse:geometry:coordinates:lon" : {"export_json" : "Non", "FR" : "lon_adresse_etalab"}, - "api_adresse:geometry:coordinates:lat" : {"export_json" : "Non", "FR" : "lat_adresse_etalab"}, - "api_adresse:properties:label" : {"export_json" : "Non", "FR" : "adresse_etalab"}, - "api_adresse:properties:score" : {"export_json" : "Non", "FR" : "score_etalab"}, - "api_adresse:properties:housenumber" : {"export_json" : "Non", "FR" : "numero_etalab"}, - "api_adresse:properties:type" : {"export_json" : "Non", "FR" : "type_etalab"}, - "api_adresse:properties:name" : {"export_json" : "Non", "FR" : "numero_et_voie_etalab"}, - "api_adresse:properties:postcode" : {"export_json" : "Non", "FR" : "code_postal_etalab"}, - "api_adresse:properties:citycode" : {"export_json" : "Non", "FR" : "code_INSEE_etalab"}, - "api_adresse:properties:city" : {"export_json" : "Non", "FR" : "ville_etalab"}, - "api_adresse:properties:street" : {"export_json" : "Non", "FR" : "rue_etalab"}, - - } - - - -requetes_overpass = { - "stationnements_velos_publics" : - { - #"critere" : '["amenity"="bicycle_parking"]["access"~"(yes|public)"]', - "critere" : """nwr["amenity"="bicycle_parking"](area:"""+aire_de_recherche+"""); - - nwr["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers)"](area:"""+aire_de_recherche+");", - "fields" : { - "amenity" : {"export_json" : "Non", "FR" : "aménagement"} , - "capacity" : {"export_json" : "Oui", "FR" : "nombre d'emplacements"}, - "access" : {"export_json" : "Oui", "FR" : "accès"}, - "bicycle_parking" : {"export_json" : "Oui", "FR" : "type"}, - "covered" : {"export_json" : "Oui", "FR" : "couvert"}, - "operator" : {"export_json" : "Oui", "FR" : "opérateur"}, - "operator:type" : {"export_json" : "Oui", "FR" : "type d'opérateur"}, - "fee" : {"export_json" : "Oui", "FR" : "frais"}, - "check_date:capacity" : {"export_json" : "Non", "FR" : "date_vérification"}, - "source" : {"export_json" : "Non", "FR" : "source"} - } - }, - - "stationnements_velos_non_publics" : - { - # "critere" : '["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers|permissive)"]', - "critere" : """nwr["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers)"](area:"""+aire_de_recherche+"); ", - "fields" : { - "amenity" : {"export_json" : "Non", "FR" : "aménagement"} , - "capacity" : {"export_json" : "Oui", "FR" : "nombre d'emplacements"}, - "access" : {"export_json" : "Oui", "FR" : "accès"}, - "bicycle_parking" : {"export_json" : "Oui", "FR" : "type"}, - "covered" : {"export_json" : "Oui", "FR" : "couvert"}, - "operator" : {"export_json" : "Oui", "FR" : "opérateur"}, - "operator:type" : {"export_json" : "Oui", "FR" : "type d'opérateur"}, - "fee" : {"export_json" : "Oui", "FR" : "frais"}, - "check_date:capacity" : {"export_json" : "Non", "FR" : "date_vérification"}, - "source" : {"export_json" : "Non", "FR" : "source"} - } - }, - - "ateliers_autoreparation" : - { - # "critere" : '["service:bicycle:diy"="yes"]', - "critere" : """nwr["service:bicycle:diy"="yes"](area:"""+aire_de_recherche+"); ", - "fields" : { - "service:bicycle:diy" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - } - }, - - "associations_velo" : - { - #"critere" : '["association"="bicycle"]', - "critere" : """nwr["association"="bicycle"](area:"""+aire_de_recherche+"); ", - "fields" : { - "association" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - } - }, - - "fabriquants_velo" : - { - #"critere" : '["craft"="bicycle"]', - "critere" : """nwr["craft"="bicycle"](area:"""+aire_de_recherche+"); ", - "fields" : { - "craft" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - - } - }, - - - "vendeurs_velo" : - { - #"critere" : '["shop"="bicycle"]', - "critere" : """nwr["shop"="bicycle"](area:"""+aire_de_recherche+"); ", - "fields" : { - "shop" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - } - }, - - "velos_libre_service" : - { - #"critere" : '["amenity"="bicycle_rental"]', - "critere" : """nwr["amenity"="bicycle_rental"](area:"""+aire_de_recherche+"); ", - "fields" : { - "amenity" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - } - }, - - - "location_velo" : - { - #"critere" : '["service:bicycle:rental"="yes"]', - "critere" : """nwr["service:bicycle:rental"="yes"](area:"""+aire_de_recherche+"); ", - "fields" : { - "service:bicycle:rental" : {"export_json" : "Non", "FR" : ""}, - "name" : {"export_json" : "Oui", "FR" : ""}, - "description" : {"export_json" : "Oui", "FR" : ""}, - "website" : {"export_json" : "Oui", "FR" : ""}, - "addr:housenumber" : {"export_json" : "Oui", "FR" : ""}, - "addr:street" : {"export_json" : "Oui", "FR" : ""}, - "addr:postcode" : {"export_json" : "Oui", "FR" : ""}, - "addr:city" : {"export_json" : "Oui", "FR" : ""}, - "contact:email" : {"export_json" : "Oui", "FR" : "email"}, - "contact:twitter" : {"export_json" : "Oui", "FR" : "Twitter"}, - "contact:facebook" : {"export_json" : "Oui", "FR" : "Facebook"}, - "contact:phone" : {"export_json" : "Oui", "FR" : "Téléphone"}, - "network" : {"export_json" : "Oui", "FR" : "Réseau"}, - "office" : {"export_json" : "Oui", "FR" : "Bureau"}, - "opening_hours" : {"export_json" : "Oui", "FR" : "Horaires"} - - } - } - - - } - - - - - # ---------------------------------------------- trad_bicycle_parking = { @@ -318,8 +110,8 @@ def executer_requete_et_exporter_resultats(nom_req, critere, aire_de_recherche, out center; """ + overpass_query = overpass_query.replace("aire_de_recherche", aire_de_recherche) - overpass_query_fields.update(api_adresse_fields) print("Execution requete overpass : \n"+overpass_query) @@ -467,14 +259,14 @@ def executer_requete_et_exporter_resultats(nom_req, critere, aire_de_recherche, -for nom_requete in requetes_overpass.keys() : +for req in requetes.reqs : for nb_essai in range(max_retry) : # on tente max_retry fois try : - executer_requete_et_exporter_resultats(nom_requete, requetes_overpass[nom_requete]["critere"], aire_de_recherche, requetes_overpass[nom_requete]["fields"]) + executer_requete_et_exporter_resultats(req.nom, req.critere, aire_de_recherche, req.champs) break