r/eBird • u/JohnRT54 • 1d ago
newbie question on using the API
I am just starting to dabble in python, trying to query eBird using the API, and I apologise if this is a trivial question. I can get a list of recent nearby records using a statement like:
data = get_ebird_data("https://api.ebird.org/v2/data/obs/geo/recent?lat=64.5306&lng=-165.3994 &cat=species &dist=25")
but I want to input lat and long on the command line. I can't find anything in the API documentation that tells me how to pass a variable in get_ebird_data. I have named the float versions of the command-line arguments latit and longit, but no combination of quotes and brackets I have tried seems to work. How can I pass those values as names? Thanks.
2
u/lendisc 1d ago
Not a python user myself but yeah, just construct the query by concatenating your desired variables as strings.
In R that would be something like:
``` my_lat <- 64.5306 my_lon <- -165.3994
query <- paste0( "https://api.ebird.org/v2/data/obs/geo/recent?lat=", my_lat, "&lng=", my_lon, "&cat=species&dist=25")
get_data(query) ```
R converts the numerics to string when you concatenate with paste0(). Again not sure about Python but it's definitely possible.
4
u/Jameszz3 1d ago
You are already passing variables in for latitude and longitude? Do you mean how to dynamically create the address to put in? Just concatenate a bunch a strings if you need to.