I am trying to create a function to loop through my list of regions and find Longitude and Latitude of them. But the problem is that I am experiencing a timeout problem, hence I want to prompt the system to sleep for about ten seconds and start again. I am not sure how to achieve this in python. I know how to do this in R but in python.
Here is my trial but i dont think this is a correct syntax, not working.
list_of_cities=["Toronto","Chelmsford","San Francisco Bay Area"]
Here is my function:
from geopy.exc import GeocoderTimedOut
from geopy.geocoders import Nominatim
import time
def findGeocode(city):
repeate(
geolocator=Nominatim(user_agent="myemail_address@gmail.com")
return geolocator.geocode(city)
if (GeocoderTimedOut):
time.sleep(10)
else
return findGeocode(city))
If this was in R, it would be something like:
repeate{
res=try(geolocator.geocode(city))
if(res="try-error)
{
sys.sleep(10)
}
else
{
break
}
}
But not sure how to do this in python.
Can anyone help me with this please?