Skip to content

Commit

Permalink
Annotate known public Nominatim servers (#488)
Browse files Browse the repository at this point in the history
Update tests to avoid hitting rate limits

Co-authored-by: Daniel McKnight <[email protected]>
  • Loading branch information
NeonDaniel and NeonDaniel authored Nov 27, 2023
1 parent 25d1a9d commit 99faae7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions neon_utils/location_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from ovos_utils.log import LOG


# geocode.maps.co nominatim.openstreetmap.org
_NOMINATIM_DOMAIN = "geocode.maps.co"


Expand Down
8 changes: 8 additions & 0 deletions tests/location_util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import unittest

from datetime import datetime
from time import sleep

from dateutil.tz import gettz, tzlocal


Expand All @@ -41,23 +43,27 @@ def test_get_coordinates_complete(self):
"country": "United States"})
self.assertIsInstance(coords[0], float)
self.assertIsInstance(coords[1], float)
sleep(1) # maps.co rate-limit

# No city specified
coords = get_coordinates({"state": "Washington",
"country": "United States"})
self.assertIsInstance(coords[0], float)
self.assertIsInstance(coords[1], float)
sleep(1) # maps.co rate-limit

# No state specified
coords = get_coordinates({"city": "Seattle",
"country": "United States"})
self.assertIsInstance(coords[0], float)
self.assertIsInstance(coords[1], float)
sleep(1) # maps.co rate-limit

# No country specified
coords = get_coordinates({"state": "Washington", "city": "Renton"})
self.assertIsInstance(coords[0], float)
self.assertIsInstance(coords[1], float)
sleep(1) # maps.co rate-limit

def test_get_location_from_coords(self):
from neon_utils.location_utils import get_location
Expand Down Expand Up @@ -106,13 +112,15 @@ def test_get_full_location(self):
self.assertEqual(location_en['address']['state'], "Washington")
self.assertEqual(location_en['address']['country'], "United States")
self.assertEqual(location_en['address']['country_code'], "us")
sleep(1) # maps.co rate-limit

location_es = get_full_location("Seattle, Washington", "es")
self.assertEqual(location_es['lat'], location_en['lat'])
self.assertEqual(location_es['lon'], location_en['lon'])
self.assertEqual(location_es['address']['country'],
"Estados Unidos de América")
self.assertEqual(location_en['address']['country_code'], "us")
sleep(1) # maps.co rate-limit

location_from_coords = get_full_location((location_en['lat'],
location_en['lon']))
Expand Down

0 comments on commit 99faae7

Please sign in to comment.