Skip to content

Commit

Permalink
Update Wolfram|Alpha to use "imperial" instead of "nonmetric" to matc…
Browse files Browse the repository at this point in the history
…h API docs

Update OWM to use onecall 3.0 as the latest
  • Loading branch information
Daniel McKnight committed May 6, 2024
1 parent 031ff19 commit 56dd92a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions neon_api_proxy/services/owm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from requests import Response

from neon_api_proxy.cached_api import CachedAPI
from ovos_utils.log import LOG
from ovos_utils.log import LOG, log_deprecation
from neon_utils.authentication_utils import find_neon_owm_key


Expand Down Expand Up @@ -81,16 +81,18 @@ def handle_query(self, **kwargs) -> dict:

def _get_api_response(self, lat: str, lng: str, units: str,
api: str = "onecall", lang: str = "en") -> Response:
str(float(lat))
str(float(lng))
if api != "onecall":
log_deprecation(f"{api} was requested but only `onecall` "
f"is supported", "1.0.0")
api = "onecall"
assert units in ("metric", "imperial", "standard")
query_params = {"lat": lat,
"lon": lng,
"appid": self._api_key,
"units": units,
"lang": lang}
query_str = urllib.parse.urlencode(query_params)
base_url = "http://api.openweathermap.org/data/2.5"
base_url = "http://api.openweathermap.org/data/3.0"
resp = self.get_with_cache_timeout(f"{base_url}/{api}?{query_str}",
self.cache_timeout)
return resp
3 changes: 2 additions & 1 deletion neon_api_proxy/services/wolfram_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _build_query_string(**kwargs) -> str:
query_params = dict()
query_params['i'] = kwargs.get("query")
query_params['units'] = kwargs.get("units") if \
kwargs.get("units") == "metric" else "nonmetric"
kwargs.get("units") == "metric" else "imperial"
lat = kwargs.get("lat")
lng = kwargs.get("lng")
if kwargs.get("latlong"):
Expand Down Expand Up @@ -156,6 +156,7 @@ def _query_api(self, query: str) -> dict:
:return: dict response containing:
`status_code`, `content`, and `encoding`
"""
LOG.debug(f"query={query}")
result = self.get_with_cache_timeout(query, timeout=self.cache_time)
if not result.ok:
# 501 = Wolfram couldn't understand
Expand Down

0 comments on commit 56dd92a

Please sign in to comment.