From a2ef91e89a93c6e07554bfa0c103ce4b07a8e6ad Mon Sep 17 00:00:00 2001 From: moanos Date: Thu, 9 Jan 2025 23:14:41 +0100 Subject: [PATCH] feat: Handle missing name --- src/fellchensammlung/tools/geo.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fellchensammlung/tools/geo.py b/src/fellchensammlung/tools/geo.py index cfaec6b..3b78a58 100644 --- a/src/fellchensammlung/tools/geo.py +++ b/src/fellchensammlung/tools/geo.py @@ -74,7 +74,10 @@ class GeoFeature: geofeatures = [] for feature in result["features"]: geojson = {} - geojson['name'] = feature["properties"]["name"] + try: + geojson['name'] = feature["properties"]["name"] + except KeyError: + geojson['name'] = feature["properties"]["street"] geojson['place_id'] = feature["properties"]["osm_id"] geojson['lat'] = feature["geometry"]["coordinates"][1] geojson['lon'] = feature["geometry"]["coordinates"][0] @@ -120,7 +123,7 @@ class GeoAPI: result = self.requests.get(self.api_url, {"q": location_string, "format": "jsonv2"}, headers=self.headers) return result.content - def get_geojson_for_query(self, location_string): + def get_geojson_for_query(self, location_string, language="de"): try: if self.api_format == 'nominatim': logging.info(f"Querying nominatim instance for: {location_string} ({self.api_url})") @@ -132,8 +135,9 @@ class GeoAPI: elif self.api_format == 'photon': logging.info(f"Querying photon instance for: {location_string} ({self.api_url})") result = self.requests.get(self.api_url, - {"q": location_string}, + {"q": location_string, "lang": language}, headers=self.headers).json() + logging.warning(result) geofeatures = GeoFeature.geofeatures_from_photon_result(result) else: raise NotImplementedError