Spaces:
Running
Running
Update geo_locate.py
Browse files- geo_locate.py +13 -4
geo_locate.py
CHANGED
|
@@ -4,10 +4,19 @@ from urllib.parse import quote
|
|
| 4 |
|
| 5 |
|
| 6 |
def get_geo_coords(address, access_token):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
rjson = json.loads(response.content)
|
| 12 |
return (float(rjson[0]['lat']), float(rjson[0]['lon']))
|
| 13 |
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def get_geo_coords(address, access_token):
|
| 7 |
+
sleep_time = 1
|
| 8 |
+
while sleep_time < 10:
|
| 9 |
+
base_url = "https://us1.locationiq.com/v1/search"
|
| 10 |
+
# headers= {"key: " + f"{access_token}", "Content-Type: application/json",}
|
| 11 |
+
url = f"{base_url}?key={access_token}&q={quote(address)}&format=json"
|
| 12 |
+
response = requests.get(url)
|
| 13 |
+
if response.status_code == 429:
|
| 14 |
+
sleep(sleep_time)
|
| 15 |
+
sleep_time *= 3
|
| 16 |
+
else:
|
| 17 |
+
break;
|
| 18 |
+
if sleep_time > 9:
|
| 19 |
+
return (0.0, 0.0)
|
| 20 |
rjson = json.loads(response.content)
|
| 21 |
return (float(rjson[0]['lat']), float(rjson[0]['lon']))
|
| 22 |
|