avryhof / ambient_api

Python module for accessing the Ambient Weather API
MIT License
31 stars 18 forks source link

access to not-most-recent-data? #15

Open ljwobker opened 1 month ago

ljwobker commented 1 month ago

Apologies for what may be the world's dumbest question (i'm new to this...)

The provided example works great grabbing the most recent data from a device. I see in the REST API docs where it supports getting historical (non instant) data via the /devices/:macAddress endpoint...

is this something that's exposed here in this super-useful python API? Or do I need to hack it up myself to build a different request when I want something other than just the devices endpoint?

avryhof commented 1 month ago

So, I think the issue is that Ambient's own documentation on this is pretty bad, and I haven't done much to improve it here.

The parameter is endDate (or end_date when passed into device.get_data())

It then returns the most recent data up to that date, since data is collected in intervals.

The other tricky part is that you pass the date in as milliseconds since the epoch.... so you would calculate it in Python like round(time.time() * 1000)

So if I were to try and get data for 5:00PM on April 26th, I would use

my_end_date = round(datetime.datetime(year=2024, month=4, day=26, hour=17, minute=0, second=0).time() * 1000)
print(device.get_data(end_date=my_end_date))