In [3]:
import zipfile
import os
from pathlib2 import Path
In [4]:
def unzip(name):
with zipfile.ZipFile(name, "r") as z:
z.extractall('unzipped')
In [5]:
if not os.path.exists('unzipped'):
os.makedirs('unzipped')
for year in range(2001, 2018):
for n_month in range(1, 13):
for state in ['wa', 'or', 'ca', 'id', 'nv', 'ut', 'az', 'nm', 'co', 'wy', 'mt', 'tx']:
month = str(n_month) if n_month > 9 else "0" + str(n_month)
file = Path("data/" + str(year) + state + month + ".zip")
if file.is_file():
unzip(file)
break
break
break
In [ ]: