-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
37 lines (32 loc) · 1.13 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import time
class ApiAvistamientos:
def __init__(self, lat, lon, delay_inicial=1):
self.lat = lat
self.lon = lon
self.delay_inicial = delay_inicial
self.url = "https://api.inaturalist.org/v1/observations"
def obtener_avistamientos(self, grupo):
"""Obtiene avistamientos para un grupo dado."""
params = {
'family': grupo,
'lat': self.lat,
'lng': self.lon,
'radius': 50,
'per_page': 10,
'order_by': 'observed_on',
'order': 'desc',
}
retries = 0
delay = self.delay_inicial
while retries < 5:
try:
response = requests.get(self.url, params=params)
response.raise_for_status()
return response.json().get('results', [])
except requests.exceptions.RequestException as e:
print(f"Error al obtener datos para {grupo}: {e}")
retries += 1
time.sleep(delay)
delay = min(delay * 2, 300)
return []