From 4e8532e9c2aeddd1c31f2a64d93715e8efd011ac Mon Sep 17 00:00:00 2001 From: antosomzi <139774463+antosomzi@users.noreply.github.com> Date: Mon, 6 May 2024 16:27:12 +0200 Subject: [PATCH] Update geocoder_api.py Upgrade the geocoding functionality in the GeocoderApi class to accommodate scenarios where only partial address information, such as city and postcode, is available. Currently, the address_with_details method raises errors when incomplete address details are provided. As most of the companies are from scrapped data or hubspot and full address is not available, we can't create new companies in the DirectoryCompany table. --- herepy/geocoder_api.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/herepy/geocoder_api.py b/herepy/geocoder_api.py index af6c8fe..2c55bce 100644 --- a/herepy/geocoder_api.py +++ b/herepy/geocoder_api.py @@ -106,8 +106,8 @@ def address_with_boundingbox( def address_with_details( self, - house_number: int, - street: str, + house_number: Optional[int] = None, + street: Optional[str] = None, city: str, country: str, lang: str = "en-US", @@ -129,11 +129,16 @@ def address_with_details( Raises: HEREError""" + qq_query = "" + if house_number is not None: + qq_query += f"houseNumber={house_number};" + if street is not None: + qq_query += f"street={street};" + qq_query += f"city={city};" + qq_query += f"country={country}" + data = { - "qq": str.format("houseNumber={0};", house_number) - + str.format("street={0};", street) - + str.format("city={0};", city) - + str.format("country={0}", country), + "qq": qq_query, "apiKey": self._api_key, "lang": lang, }