Skip to content

Commit fe7acf2

Browse files
authored
0.6.0 (#97)
2 parents 6bda638 + ba62d24 commit fe7acf2

File tree

10 files changed

+66
-27
lines changed

10 files changed

+66
-27
lines changed

CHANGELOG.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
# Changelog
22

3-
## [0.4.3a2](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.4.3a2) (2024-02-26)
3+
## [0.6.0](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.6.0) (2024-06-17)
44

5-
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.4.3a1...0.4.3a2)
5+
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a3...0.6.0)
6+
7+
**Implemented enhancements:**
8+
9+
- \[FEAT\] Add Daily and Hourly Weather API calls [\#71](https://github.com/NeonGeckoCom/neon_api_proxy/issues/71)
10+
- Handle requests for unauthenticated APIs [\#21](https://github.com/NeonGeckoCom/neon_api_proxy/issues/21)
11+
12+
## [0.5.1a3](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a3) (2024-05-07)
13+
14+
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a2...0.5.1a3)
15+
16+
**Merged pull requests:**
17+
18+
- Update W|A and OWM wrappers to match upstream APIs [\#96](https://github.com/NeonGeckoCom/neon_api_proxy/pull/96) ([NeonDaniel](https://github.com/NeonDaniel))
19+
20+
## [0.5.1a2](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a2) (2024-04-25)
21+
22+
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a1...0.5.1a2)
623

724
**Merged pull requests:**
825

9-
- Update geolocation tests [\#91](https://github.com/NeonGeckoCom/neon_api_proxy/pull/91) ([NeonDaniel](https://github.com/NeonDaniel))
26+
- feat: allow ovos-utils 0.1.0 [\#94](https://github.com/NeonGeckoCom/neon_api_proxy/pull/94) ([mikejgray](https://github.com/mikejgray))
1027

11-
## [0.4.3a1](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.4.3a1) (2023-12-28)
28+
## [0.5.1a1](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a1) (2024-04-09)
1229

13-
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.4.2...0.4.3a1)
30+
[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.0...0.5.1a1)
1431

1532
**Merged pull requests:**
1633

17-
- Add Map Maker API with unit tests [\#88](https://github.com/NeonGeckoCom/neon_api_proxy/pull/88) ([NeonDaniel](https://github.com/NeonDaniel))
34+
- OWM language handling [\#93](https://github.com/NeonGeckoCom/neon_api_proxy/pull/93) ([NeonDaniel](https://github.com/NeonDaniel))
1835

1936

2037

neon_api_proxy/api_connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def handle_api_input(self,
7676
LOG.info(f"request={request}")
7777

7878
respond = self.proxy.resolve_query(request)
79-
LOG.info(f"message={message_id} "
80-
f"status={respond.get('status_code')}")
79+
LOG.debug(f"response message={message_id} "
80+
f"status={respond.get('status_code')}")
8181

8282
try:
8383
respond['content'] = bytes(respond.get('content', b'')).\
@@ -121,7 +121,7 @@ def extract_agent_tokens(msg_data: dict) -> dict:
121121
tokens['message_id'] = tokens['replied_message'] = \
122122
msg_data.get('messageID', None)
123123
else:
124-
LOG.warning('Failed to resolve an agent from the message data')
124+
LOG.debug('No valid agent specified in the message data')
125125
return tokens
126126

127127
def handle_error(self, thread, exception):

neon_api_proxy/client/open_weather_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ def _make_api_call(lat: Union[str, float], lng: Union[str, float],
104104
except JSONDecodeError:
105105
data = {"error": "Error decoding response",
106106
"response": resp}
107+
if data.get('cod') == "400":
108+
# Backwards-compat. Put error response under `error` key
109+
data["error"] = data.get("message")
107110
if data.get('cod'):
108111
data['cod'] = str(data['cod'])
109112
# TODO: Handle failures

neon_api_proxy/controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ def init_service_instances(self, service_class_mapping: dict) -> dict:
8989
api_key = self.config.get(item, {}).get("api_key") if self.config \
9090
else None
9191
try:
92-
if api_key is None:
93-
LOG.warning(f"No API key for {item} in {self.config}")
92+
if api_key is None and item != 'api_test_endpoint':
93+
LOG.warning(f"No API key for {item} in "
94+
f"{list(self.config.keys())}")
9495
service_mapping[item] = \
9596
service_class_mapping[item](api_key=api_key)
9697
except Exception as e:

neon_api_proxy/services/owm_api.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from requests import Response
3333

3434
from neon_api_proxy.cached_api import CachedAPI
35-
from ovos_utils.log import LOG
35+
from ovos_utils.log import LOG, log_deprecation
3636
from neon_utils.authentication_utils import find_neon_owm_key
3737

3838

@@ -60,35 +60,45 @@ def handle_query(self, **kwargs) -> dict:
6060
lat = kwargs.get("lat")
6161
lng = kwargs.get("lng", kwargs.get("lon"))
6262
api = kwargs.get('api') or "onecall"
63+
lang = kwargs.get('lang') or "en"
6364
units = "metric" if kwargs.get("units") == "metric" else "imperial"
6465

6566
if not all((lat, lng, units)):
6667
return {"status_code": -1,
6768
"content": f"Missing required args in: {kwargs}",
6869
"encoding": None}
6970
try:
70-
resp = self._get_api_response(lat, lng, units, api)
71+
resp = self._get_api_response(lat, lng, units, api, lang)
7172
except Exception as e:
7273
return {"status_code": -1,
7374
"content": repr(e),
7475
"encoding": None}
7576
if not resp.ok:
76-
LOG.error(f"Bad response code: {resp.status_code}")
77+
LOG.error(f"Bad response code: {resp.status_code}: "
78+
f"content={resp.content}")
7779
return {"status_code": resp.status_code,
7880
"content": resp.content,
7981
"encoding": resp.encoding}
8082

8183
def _get_api_response(self, lat: str, lng: str, units: str,
82-
api: str = "onecall") -> Response:
83-
str(float(lat))
84-
str(float(lng))
84+
api: str = "onecall", lang: str = "en") -> Response:
85+
try:
86+
assert isinstance(float(lat), float), f"Invalid latitude: {lat}"
87+
assert isinstance(float(lng), float), f"Invalid longitude: {lng}"
88+
except AssertionError as e:
89+
raise ValueError(e)
90+
if api != "onecall":
91+
log_deprecation(f"{api} was requested but only `onecall` "
92+
f"is supported", "1.0.0")
93+
api = "onecall"
8594
assert units in ("metric", "imperial", "standard")
8695
query_params = {"lat": lat,
8796
"lon": lng,
8897
"appid": self._api_key,
89-
"units": units}
98+
"units": units,
99+
"lang": lang}
90100
query_str = urllib.parse.urlencode(query_params)
91-
base_url = "http://api.openweathermap.org/data/2.5"
101+
base_url = "http://api.openweathermap.org/data/3.0"
92102
resp = self.get_with_cache_timeout(f"{base_url}/{api}?{query_str}",
93103
self.cache_timeout)
94104
return resp

neon_api_proxy/services/wolfram_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _build_query_string(**kwargs) -> str:
9292
query_params = dict()
9393
query_params['i'] = kwargs.get("query")
9494
query_params['units'] = kwargs.get("units") if \
95-
kwargs.get("units") == "metric" else "nonmetric"
95+
kwargs.get("units") == "metric" else "imperial"
9696
lat = kwargs.get("lat")
9797
lng = kwargs.get("lng")
9898
if kwargs.get("latlong"):
@@ -156,6 +156,7 @@ def _query_api(self, query: str) -> dict:
156156
:return: dict response containing:
157157
`status_code`, `content`, and `encoding`
158158
"""
159+
LOG.debug(f"query={query}")
159160
result = self.get_with_cache_timeout(query, timeout=self.cache_time)
160161
if not result.ok:
161162
# 501 = Wolfram couldn't understand

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
requests-cache~=0.6,>=0.6.4
22
requests~=2.20
33
neon_utils[network]~=1.0
4-
ovos-utils~=0.0.31
4+
ovos-utils>=0.0.31,<0.2.0
55
ovos-config~=0.0.10
66
neon-mq-connector~=0.7

tests/test_owm_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ def test_handle_query_valid_onecall(self):
112112
self.assertEqual(resp["encoding"], "utf-8")
113113
self.assertIsInstance(json.loads(resp["content"]), dict)
114114

115+
spanish = self.api.handle_query(**VALID_QUERY_ONECALL, lang="es")
116+
self.assertIsInstance(spanish, dict)
117+
self.assertEqual(spanish["status_code"], 200)
118+
self.assertEqual(spanish["encoding"], "utf-8")
119+
self.assertIsInstance(json.loads(spanish["content"]), dict)
120+
self.assertNotEqual(spanish, resp)
121+
115122
def test_handle_query_valid_current(self):
116123
resp = self.api.handle_query(**VALID_QUERY_CURRENT)
117124
self.assertIsInstance(resp, dict)

tests/test_wolfram_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
"ip": "50.47.129.133"}
4040

4141
VALID_QUERY_LAT_LON = {"query": "how far away is new york?",
42-
"units": "nonmetric",
42+
"units": "imperial",
4343
"lat": "47.4797",
4444
"lng": "122.2079"}
4545

4646
VALID_QUERY_LAT_LON_IP = {"query": "how far away is Bellevue?",
47-
"units": "nonmetric",
47+
"units": "nonmetric", # Test backwards-compat.
4848
"lat": "47.4797",
4949
"lng": "122.2079",
5050
"ip": "50.47.129.133"}
@@ -86,19 +86,19 @@ def test_build_query_url_invalid_param_types(self):
8686

8787
def test_build_query_string_valid_minimal(self):
8888
query_str = self.api._build_query_string(**VALID_QUERY_MINIMAL)
89-
self.assertEqual(query_str, f"i=how+far+away+is+Miami%3F&units=nonmetric")
89+
self.assertEqual(query_str, f"i=how+far+away+is+Miami%3F&units=imperial")
9090

9191
def test_build_query_string_valid_lat_lng(self):
9292
query_str = self.api._build_query_string(**VALID_QUERY_LAT_LON)
93-
self.assertEqual(query_str, f"i=how+far+away+is+new+york%3F&units=nonmetric&latlong=47.4797%2C122.2079")
93+
self.assertEqual(query_str, f"i=how+far+away+is+new+york%3F&units=imperial&latlong=47.4797%2C122.2079")
9494

9595
def test_build_query_string_valid_ip(self):
9696
query_str = self.api._build_query_string(**VALID_QUERY_IP)
9797
self.assertEqual(query_str, f"i=how+far+away+is+Moscow%3F&units=metric&ip=50.47.129.133")
9898

9999
def test_build_query_string_valid_lat_lng_ip(self):
100100
query_str = self.api._build_query_string(**VALID_QUERY_LAT_LON_IP)
101-
self.assertEqual(query_str, f"i=how+far+away+is+Bellevue%3F&units=nonmetric&latlong=47.4797%2C122.2079")
101+
self.assertEqual(query_str, f"i=how+far+away+is+Bellevue%3F&units=imperial&latlong=47.4797%2C122.2079")
102102

103103
def test_build_query_invalid_query(self):
104104
with self.assertRaises(ValueError):

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
__version__ = "0.5.0"
29+
__version__ = "0.6.0"

0 commit comments

Comments
 (0)