file.extractall(filepath + '/NC_VTD') os.remove(f'{full_path}/{zip_name}') if response.status_code == 404: print(f'404 returned for {state_abbreviation}.') return def download_mggg_state(state_abbreviation, filepath): # If directory doesn't exist, create it full_path = filepath + f'/precincts-elections/{state_abbreviation}_VTD' if not os.path.exists(full_path): os.mkdir(full_path) # Download metadata and save to constants.py data_dict = get_mggg_states_metadata(state_abbreviation) with open(f'{full_path}/metadata.py', 'w') as file: file.write(f'DATA_DICT = {data_dict}') # Download shapefile and election data download_mggg_shapefile(state_abbreviation, filepath) if __name__ == '__main__': state_abbvreviations = STATES.values() for abbreviation in list(state_abbvreviations): download_mggg_state_zip(abbreviation, data_path)