Python code using API to get historical data

Here is Python code to download historical PurpleAir data with new AQI. Test it to find bugs.
Thank you!!

1 Like

Thanks, nice work!

Does there exist or is there an example to filter the request download for the following?

  • only primary sensor (A not redundant B)
  • ‘outside’ sensors (not ‘inside’)

Also, would another approach to purple air data download for larger regional analysis to download larger areas by some time interval(day/month/year/etc) and share the downloaded results on github or shared google drive than repeatedly tax the API for the same historical regional datasets?

What would the average daily amount of data collected by all purple air sensors currently be? I would guess less than a gigabyte/day.

Thanks,
Jeremy

Hi Jeremy,

I have updated the script to reflect choices of ‘location_type’ as indoor/outdoor/both. Please refer to the script lines: 27, 51-57, 60, 172-173.

Regarding only primary sensors data (A) then you need to provide only fields from sensor A . Please refer to the document and search ‘fields’ for more options. Loading...

The size of the data depends on minutes, hourly, daily, period of data and number of monitors.

Let me know if above works for you.
Thanks!

Hi Zuber, I have been working with your script but I have trouble on this line
engine = create_engine(‘postgresql://postgres:password@location:port/database’)
could you please tell me what user, password, location, and port this line is referring to?

thanks in advance

Hi Fernando,

The ‘engine’ is created if you are using SQL database to save downloads in a table. In my case, I am using PostgreSQL to save data in tables. More information about SQLAlchemy can be found at Engine Configuration — SQLAlchemy 1.4 Documentation

If you just need the data in CSV then comment lines #: 19, 22, 74, and 160.

Let me know if this works.

Thanks!

Hi Zuber
It runs well, Thank you.
About the field list, I had to change ‘humidity_a’, ‘humidity_b’ to ‘humidity’, ‘humidity_a’ in order to get both measurements (the same for temp ann pressure)

Hi Fernando,

I am glad that it worked for you. Heads up about humidity and other fields.

Variations:
humidity returns average for channel A and B.
humidity_a returns channel A data.
humidity_b returns channel B data.

Thanks!