Use 'postalcode' parameter when a zipcode is used to get more accurate results. Added previously removed test.
parent
77133f7cf3
commit
f02bcae388
|
@ -28,6 +28,7 @@ class TestWeather(unittest.TestCase):
|
||||||
('27959', check_places("Dare County", "North Carolina")),
|
('27959', check_places("Dare County", "North Carolina")),
|
||||||
('48067', check_places("Royal Oak", "Michigan")),
|
('48067', check_places("Royal Oak", "Michigan")),
|
||||||
('23606', check_places("Newport News", "Virginia")),
|
('23606', check_places("Newport News", "Virginia")),
|
||||||
|
('23113', check_places("Midlothian", "Virginia")),
|
||||||
('27517', check_places("Chapel Hill", "North Carolina")),
|
('27517', check_places("Chapel Hill", "North Carolina")),
|
||||||
('15213', check_places("Allegheny County", "Pennsylvania")),
|
('15213', check_places("Allegheny County", "Pennsylvania")),
|
||||||
('90210', check_places("Los Angeles County", "California")),
|
('90210', check_places("Los Angeles County", "California")),
|
||||||
|
|
|
@ -17,8 +17,14 @@ r_from = re.compile(r'(?i)([+-]\d+):00 from')
|
||||||
|
|
||||||
|
|
||||||
def location(q):
|
def location(q):
|
||||||
uri = 'https://nominatim.openstreetmap.org/search/?q={query}&format=json'.\
|
uri = 'https://nominatim.openstreetmap.org/search?%s={query}&format=json'
|
||||||
format(query=web.quote(q))
|
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)
|
results = web.get(uri)
|
||||||
data = json.loads(results)
|
data = json.loads(results)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue