Last active
July 24, 2018 11:40
-
-
Save jcarlosroldan/ed5926a84e980922bea5b6a0e4380744 to your computer and use it in GitHub Desktop.
Geocode a place and retry everytime it fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from geopy.exc import GeocoderTimedOut | |
from geopy.geocoders import Nominatim | |
# Choose your preferred geocoder at http://geopy.readthedocs.io/en/latest/#module-geopy.geocoders | |
_geo = Nominatim() | |
def where(place, timeout=10): | |
res = None | |
while res == None: | |
try: | |
res = _geo.geocode(place, timeout=timeout) | |
except GeocoderTimedOut: | |
print("Geocoding failed for %s. Retrying..." % place) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment