Skip to content

Instantly share code, notes, and snippets.

@ryanohs
Created September 9, 2023 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanohs/b59b639c38a3158f158c9ed1e31f787b to your computer and use it in GitHub Desktop.
Save ryanohs/b59b639c38a3158f158c9ed1e31f787b to your computer and use it in GitHub Desktop.
Download AQI annual summary files from the EPA
#!/bin/bash
# Define the base URL for the zip files
base_url="https://aqs.epa.gov/aqsweb/airdata/annual_aqi_by_county_"
# Define the range of years (from 2000 to 2022 in this example)
start_year=2015
end_year=2022
# Define the directory where you want to store the downloaded zip files
download_dir="zips"
# Define the directory where you want to extract the zip files
extract_dir="data"
# Loop through the years and download/unzip the files
for year in $(seq "$start_year" "$end_year"); do
zip_url="${base_url}${year}.zip"
zip_file="${download_dir}/annual_aqi_by_county_${year}.zip"
# Download the zip file
curl "$zip_url" -o "$zip_file"
# Unzip the downloaded file
unzip "$zip_file" -d "$extract_dir"
# Optionally, move the contents of the extracted files to another directory
# mv "$extract_dir/contents" "/path/to/destination/directory"
# Optionally, delete the downloaded zip file after extraction
# rm "$zip_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment