Downloader for AirNow

Toolkit and API for downloading AirNow

class AirNowDownloader(target: Optional[str] = None, parameter: Optional[str] = None, api_key: Optional[str] = None, qc=None, context: Optional[AirNowContext] = None)[source]

Main class to download AirNow data

Constructor.

Parameters:
  • target – File name, where downloaded data is saved. If file name includes substring “.json”, then the data is saved in JSON format, otherwise it is saved as CSV. If target is not specified (None), then the data is not saved to file but is returned to the caller. The latter mode is useful for testing.

  • parameter

    Comma-separated list of parameters to download. In practice because of AirNow API limitations, if more than one parameter is specified, a runtime error will occur. Possible values:

    • Ozone (O3, ozone)

    • PM2.5 (pm25)

    • PM10 (pm10)

    • CO (co)

    • NO2 (no2)

    • SO2 (so2)

  • api_key – Optional API Key to use with AirNow api. If not specified, then it is searched in a file named .airnow.yaml or .airnow.json first in working directory and then in user’s home directory

download(requested_date) Union[List[dict], str][source]

Download data for a date

Parameters:

requested_date – date to be downloaded

Returns:

If target has been specified, then this method returns the target file name, otherwise it returns a list of dictionaries where each dictionary is structured as JSON, with column names serving as keys

static dump_csv(output, rows)[source]

Internal method used by download Dumps rows as CSV file

write_csv_header(row)[source]

Internal method used by download Writes CSV file ehader

process(content: str) List[dict][source]

Internal method

Aggregates hourly data into day’s averages and joins with geographic information such as state, county, zip code.

Parameters:

content – Raw content received from AirNow API call see: https://docs.airnowapi.org/Data/docs

Returns:

List of dictinaries, where each row is represented as a dictionary, with column names serving as keys

download_range(start_date, end_date=datetime.date(2024, 6, 8))[source]

Downloads data for a range of dates. To invoke this method the application must have specified a target file

Parameters:
  • start_date – First date in the range to download (inclusive)

  • end_date – Last date in the range to download (inclusive)