Use 'postalcode' parameter when a zipcode is used to get more accurate results. Added previously removed test.

master
Paul Walko 2017-02-17 19:43:28 +00:00
parent 77133f7cf3
commit f02bcae388
2 changed files with 9 additions and 2 deletions

View File

@ -28,6 +28,7 @@ class TestWeather(unittest.TestCase):
('27959', check_places("Dare County", "North Carolina")),
('48067', check_places("Royal Oak", "Michigan")),
('23606', check_places("Newport News", "Virginia")),
('23113', check_places("Midlothian", "Virginia")),
('27517', check_places("Chapel Hill", "North Carolina")),
('15213', check_places("Allegheny County", "Pennsylvania")),
('90210', check_places("Los Angeles County", "California")),

View File

@ -17,8 +17,14 @@ r_from = re.compile(r'(?i)([+-]\d+):00 from')
def location(q):
uri = 'https://nominatim.openstreetmap.org/search/?q={query}&format=json'.\
format(query=web.quote(q))
uri = 'https://nominatim.openstreetmap.org/search?%s={query}&format=json'
if q.isdigit():
uri = uri % 'postalcode'
else:
uri = uri % 'q'
uri = uri . format(query = web.quote(q))
# uri = 'https://nominatim.openstreetmap.org/search/?q={query}&format=json'.\
# format(query=web.quote(q))
results = web.get(uri)
data = json.loads(results)