From aa39eb2bdfe499154001dcdfba2e5ab1c1d36043 Mon Sep 17 00:00:00 2001 From: Theja Putta Date: Sun, 27 Aug 2023 21:38:35 -0600 Subject: [PATCH] download fars data --- general/update_fars/01_download_fars.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 general/update_fars/01_download_fars.py diff --git a/general/update_fars/01_download_fars.py b/general/update_fars/01_download_fars.py new file mode 100644 index 0000000..4e4ced5 --- /dev/null +++ b/general/update_fars/01_download_fars.py @@ -0,0 +1,15 @@ +from urllib import request +import os + +# place to save data locally +data_folder = "/mnt/c/Users/tputta/OneDrive - Toole Design/Desktop/SSPF/FARS" + +start_yr = 2015 +end_yr = 2021 + +for yr in range(start_yr, end_yr+1): + print(f"Downloading {yr} FARS data") + if not os.path.exists(f"{data_folder}/{yr}"): + os.mkdir(f"{data_folder}/{yr}") + request.urlretrieve(f"https://static.nhtsa.gov/nhtsa/downloads/FARS/{yr}/National/FARS{yr}NationalCSV.zip", f"{data_folder}/{yr}/FARS{yr}NationalCSV.zip") + yr += 1 \ No newline at end of file