From 769c0b8cdfc68e98bd51b306deaade2286f2e70c Mon Sep 17 00:00:00 2001 From: SebF Date: Sun, 3 Oct 2021 15:42:12 +0200 Subject: [PATCH] import des erreurs dans le script principal --- recup_donnees_OSM_Overpass.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/recup_donnees_OSM_Overpass.py b/recup_donnees_OSM_Overpass.py index fc2bc3f..afbb958 100644 --- a/recup_donnees_OSM_Overpass.py +++ b/recup_donnees_OSM_Overpass.py @@ -21,6 +21,7 @@ import time from pyexcel_ods3 import save_data from collections import OrderedDict import os +from osm_vc63 import errors overpass_url="http://overpass-api.de/api/interpreter" geo_api_url = "https://api-adresse.data.gouv.fr" @@ -279,29 +280,12 @@ trad_bicycle_parking = { # ---------------------------------------------- -class Api_error(Exception) : - def __init__(self, http_code, message="erreur appel API"): - self.http_code = http_code - self.message = message - super().__init__(self.message) - - def __str__(self): - return f'{self.http_code} -> {self.message}' - -class Overpass_error(Api_error) : - pass - -class Geo_api_error(Api_error) : - pass - -# ---------------------------------------------- - def run_overpass_query(query) : response = requests.get(overpass_url, params={'data': query}) if (response.status_code != 200) : - raise Overpass_error(response.status_code) + raise errors.Overpass_error(response.status_code) return (response.json()) @@ -313,7 +297,7 @@ def run_reverse_geocoding(lat, lon) : response = requests.get(url, params={'lon' : str(lon), 'lat' : str(lat)}) if (response.status_code != 200) : - raise Geo_api_error(response.status_code) + raise errors.Geo_api_error(response.status_code) return (response.json()) @@ -495,7 +479,7 @@ for nom_requete in requetes_overpass.keys() : break - except Api_error : + except errors.Api_error : if (nb_essai == max_retry) : print ("trop d'erreurs d'API - abandon")