diff --git a/neon_api_proxy/api_connector.py b/neon_api_proxy/api_connector.py index 7bc5e2d..2249b2b 100644 --- a/neon_api_proxy/api_connector.py +++ b/neon_api_proxy/api_connector.py @@ -76,8 +76,8 @@ def handle_api_input(self, LOG.info(f"request={request}") respond = self.proxy.resolve_query(request) - LOG.info(f"message={message_id} " - f"status={respond.get('status_code')}") + LOG.debug(f"response message={message_id} " + f"status={respond.get('status_code')}") try: respond['content'] = bytes(respond.get('content', b'')).\ @@ -121,7 +121,7 @@ def extract_agent_tokens(msg_data: dict) -> dict: tokens['message_id'] = tokens['replied_message'] = \ msg_data.get('messageID', None) else: - LOG.warning('Failed to resolve an agent from the message data') + LOG.debug('No valid agent specified in the message data') return tokens def handle_error(self, thread, exception): diff --git a/neon_api_proxy/services/owm_api.py b/neon_api_proxy/services/owm_api.py index bc845dd..d13603f 100644 --- a/neon_api_proxy/services/owm_api.py +++ b/neon_api_proxy/services/owm_api.py @@ -60,6 +60,7 @@ def handle_query(self, **kwargs) -> dict: lat = kwargs.get("lat") lng = kwargs.get("lng", kwargs.get("lon")) api = kwargs.get('api') or "onecall" + lang = kwargs.get('lang') or "en" units = "metric" if kwargs.get("units") == "metric" else "imperial" if not all((lat, lng, units)): @@ -67,7 +68,7 @@ def handle_query(self, **kwargs) -> dict: "content": f"Missing required args in: {kwargs}", "encoding": None} try: - resp = self._get_api_response(lat, lng, units, api) + resp = self._get_api_response(lat, lng, units, api, lang) except Exception as e: return {"status_code": -1, "content": repr(e), @@ -79,14 +80,15 @@ def handle_query(self, **kwargs) -> dict: "encoding": resp.encoding} def _get_api_response(self, lat: str, lng: str, units: str, - api: str = "onecall") -> Response: + api: str = "onecall", lang: str = "en") -> Response: str(float(lat)) str(float(lng)) assert units in ("metric", "imperial", "standard") query_params = {"lat": lat, "lon": lng, "appid": self._api_key, - "units": units} + "units": units, + "lang": lang} query_str = urllib.parse.urlencode(query_params) base_url = "http://api.openweathermap.org/data/2.5" resp = self.get_with_cache_timeout(f"{base_url}/{api}?{query_str}", diff --git a/tests/test_owm_api.py b/tests/test_owm_api.py index 87cd2c0..c2e0a2a 100644 --- a/tests/test_owm_api.py +++ b/tests/test_owm_api.py @@ -112,6 +112,13 @@ def test_handle_query_valid_onecall(self): self.assertEqual(resp["encoding"], "utf-8") self.assertIsInstance(json.loads(resp["content"]), dict) + spanish = self.api.handle_query(**VALID_QUERY_ONECALL, lang="es") + self.assertIsInstance(spanish, dict) + self.assertEqual(spanish["status_code"], 200) + self.assertEqual(spanish["encoding"], "utf-8") + self.assertIsInstance(json.loads(spanish["content"]), dict) + self.assertNotEqual(spanish, resp) + def test_handle_query_valid_current(self): resp = self.api.handle_query(**VALID_QUERY_CURRENT) self.assertIsInstance(resp, dict)