ebird-api icon indicating copy to clipboard operation
ebird-api copied to clipboard

Add rank parameter to get_historic_observations

Open gbabineau opened this issue 11 months ago • 0 comments

This PR addresses #25 which I created. I needed to get the first observation of a taxa on the date specified for get_historic_observations. This functionality is provided in the eBird API but was not made available in this python wrapper.

I attempted to follow the coding standards. The changes are simple.

I also tested that the existing functionality still works - either as default, or by passing the parameter it had been defaulting to.

I hope this is useful! I appreciate the work to put this wrapper together and am glad to contribute back.

# demonstrate that existing functionality is still supported when no rank is supplied
# It should print a time when the Clapper Rail was seen at the end of the day
observations = get_historic_observations(
    token=ebird_api_key, area='US-VA-003', date=date(2021, 4, 9), category="species"
)
clapper_rail_obs = next((obs for obs in observations if obs.get('comName') == 'Clapper Rail'), None)
print(clapper_rail_obs.get('obsDt'))

# demonstrate that new functionality is supported when rank=="create
# It should print a time when the Clapper Rail was seen at the beginning of the day
observations = get_historic_observations(
    token=ebird_api_key, area='US-VA-003', date=date(2021, 4, 9), category="species", rank="create"
)
clapper_rail_obs = next(
    (obs for obs in observations if obs.get("comName") == "Clapper Rail"), None
)
print(clapper_rail_obs.get("obsDt"))

# demonstrate that new functionality is supported when rank=="mrec"
# It should print a time when the Clapper Rail was seen at the end of the day
observations = get_historic_observations(
    token=ebird_api_key, area='US-VA-003', date=date(2021, 4, 9), category="species", rank="mrec"
)
clapper_rail_obs = next(
    (obs for obs in observations if obs.get("comName") == "Clapper Rail"), None
)
print(clapper_rail_obs.get("obsDt"))

and the results are correct, showing evening, morning, evening.

2021-04-09 19:15
2021-04-09 07:08
2021-04-09 19:15

gbabineau avatar Mar 25 '25 22:03 gbabineau