import des erreurs dans le script principal
This commit is contained in:
parent
90201923be
commit
769c0b8cdf
@ -21,6 +21,7 @@ import time
|
|||||||
from pyexcel_ods3 import save_data
|
from pyexcel_ods3 import save_data
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import os
|
import os
|
||||||
|
from osm_vc63 import errors
|
||||||
|
|
||||||
overpass_url="http://overpass-api.de/api/interpreter"
|
overpass_url="http://overpass-api.de/api/interpreter"
|
||||||
geo_api_url = "https://api-adresse.data.gouv.fr"
|
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) :
|
def run_overpass_query(query) :
|
||||||
|
|
||||||
response = requests.get(overpass_url, params={'data': query})
|
response = requests.get(overpass_url, params={'data': query})
|
||||||
|
|
||||||
if (response.status_code != 200) :
|
if (response.status_code != 200) :
|
||||||
raise Overpass_error(response.status_code)
|
raise errors.Overpass_error(response.status_code)
|
||||||
|
|
||||||
return (response.json())
|
return (response.json())
|
||||||
|
|
||||||
@ -313,7 +297,7 @@ def run_reverse_geocoding(lat, lon) :
|
|||||||
response = requests.get(url, params={'lon' : str(lon), 'lat' : str(lat)})
|
response = requests.get(url, params={'lon' : str(lon), 'lat' : str(lat)})
|
||||||
|
|
||||||
if (response.status_code != 200) :
|
if (response.status_code != 200) :
|
||||||
raise Geo_api_error(response.status_code)
|
raise errors.Geo_api_error(response.status_code)
|
||||||
|
|
||||||
return (response.json())
|
return (response.json())
|
||||||
|
|
||||||
@ -495,7 +479,7 @@ for nom_requete in requetes_overpass.keys() :
|
|||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
except Api_error :
|
except errors.Api_error :
|
||||||
|
|
||||||
if (nb_essai == max_retry) :
|
if (nb_essai == max_retry) :
|
||||||
print ("trop d'erreurs d'API - abandon")
|
print ("trop d'erreurs d'API - abandon")
|
||||||
|
Loading…
Reference in New Issue
Block a user