diff --git a/modules/llm.py b/modules/llm.py index b575620..e58f4d3 100644 --- a/modules/llm.py +++ b/modules/llm.py @@ -100,7 +100,7 @@ def llm_query(input, nodeID=0, location_name=None): else: googleResults = ['no other context provided'] except Exception as e: - logger.debug(f"System: LLM Query: context gathering error: {e}") + logger.debug(f"System: LLM Query: context gathering failed, likely due to network issues") googleResults = ['no other context provided'] diff --git a/modules/locationdata.py b/modules/locationdata.py index 4937adc..259b700 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -22,28 +22,33 @@ def where_am_i(lat=0, lon=0, short=False): # initialize Nominatim API geolocator = Nominatim(user_agent="mesh-bot") - # Nomatim API call to get address - if short: - location = geolocator.reverse(lat + ", " + lon) - address = location.raw['address'] - address_components = ['city', 'state', 'county', 'country'] - whereIam = f"City: {address.get('city', '')} State: {address.get('state', '')} County: {address.get('county', '')} Country: {address.get('country', '')}" + try: + # Nomatim API call to get address + if short: + location = geolocator.reverse(lat + ", " + lon) + address = location.raw['address'] + address_components = ['city', 'state', 'county', 'country'] + whereIam = f"City: {address.get('city', '')} State: {address.get('state', '')} County: {address.get('county', '')} Country: {address.get('country', '')}" + return whereIam + + if float(lat) == latitudeValue and float(lon) == longitudeValue: + # redacted address when no GPS and using default location + location = geolocator.reverse(lat + ", " + lon) + address = location.raw['address'] + address_components = ['city', 'state', 'postcode', 'county', 'country'] + whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) + whereIam += " Grid: " + grid + else: + location = geolocator.reverse(lat + ", " + lon) + address = location.raw['address'] + address_components = ['house_number', 'road', 'city', 'state', 'postcode', 'county', 'country'] + whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) + whereIam += " Grid: " + grid return whereIam + except Exception as e: + logger.debug("Location:Error fetching location data with whereami, likely network error") + return ERROR_FETCHING_DATA - if float(lat) == latitudeValue and float(lon) == longitudeValue: - # redacted address when no GPS and using default location - location = geolocator.reverse(lat + ", " + lon) - address = location.raw['address'] - address_components = ['city', 'state', 'postcode', 'county', 'country'] - whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) - whereIam += " Grid: " + grid - else: - location = geolocator.reverse(lat + ", " + lon) - address = location.raw['address'] - address_components = ['house_number', 'road', 'city', 'state', 'postcode', 'county', 'country'] - whereIam += ' '.join([address.get(component, '') for component in address_components if component in address]) - whereIam += " Grid: " + grid - return whereIam def get_tide(lat=0, lon=0): station_id = ""