forked from Olav63/outils_OSM
correction de l'appel : header manquant
This commit is contained in:
parent
dfd8d264b4
commit
bebc0602a9
@ -237,7 +237,7 @@ class Utils:
|
||||
|
||||
return data
|
||||
|
||||
def geocodage_csv(self, data2):
|
||||
def geocodage_csv(self, data):
|
||||
"""
|
||||
Renseigne une adresse pour chaque élément de data
|
||||
en une fois via csv
|
||||
@ -245,11 +245,12 @@ class Utils:
|
||||
|
||||
url = self.geo_api_url + "/reverse/csv/"
|
||||
|
||||
with open("output.csv", "w", newline="") as data_to_file:
|
||||
# création du fichier à envoyer à l'API
|
||||
with open("tmp_geocodage.csv", "w", newline="") as tmp_csv_file:
|
||||
csv_writer = csv.writer(tmp_csv_file)
|
||||
csv_writer.writerow(["lat", "lon"])
|
||||
|
||||
csv_writer = csv.writer(data_to_file)
|
||||
|
||||
for element in data2["elements"]:
|
||||
for element in data["elements"]:
|
||||
if element["type"] == "node":
|
||||
csv_writer.writerow([element["lat"], element["lon"]])
|
||||
else:
|
||||
@ -257,21 +258,20 @@ class Utils:
|
||||
[element["center"]["lat"], element["center"]["lon"]]
|
||||
)
|
||||
|
||||
response = requests.post(
|
||||
url,
|
||||
files=OrderedDict(
|
||||
[("data", ("output.csv", open("output.csv", "rb").read()))]
|
||||
),
|
||||
# préparation et envoi de la requête
|
||||
payload = dict(
|
||||
[("data", ("tmp_geocodage.csv", open("tmp_geocodage.csv", "rb").read()))]
|
||||
)
|
||||
response = requests.post(url, files=payload)
|
||||
|
||||
os.remove("tmp_geocodage.csv")
|
||||
|
||||
if response.status_code != 200:
|
||||
raise errors.GeoApiError(response.status_code)
|
||||
|
||||
print(response)
|
||||
|
||||
logging.info("Géocodage inversé terminé")
|
||||
|
||||
return data2
|
||||
return data
|
||||
|
||||
def traduction(self, tag, dictionnaire, data):
|
||||
"""Traduit le champ tag des éléments de data avec dict"""
|
||||
|
Loading…
Reference in New Issue
Block a user