+
+def download_sf1(states):
+ """
+ Download the Summary File 1 geo file for each state.
+ """
+
+ for state in states:
+ # First, create the blocks data path if it doesn't exist.
+ FileUtils.mkdir_p(state.sf1_data_path(), 0755)
+
+ if not os.path.exists(state.sf1_geo_file_path()):
+ url = state.sf1_data_url()
+ tmpfile = state.sf1_zipfile_name()
+ print "Grabbing SF1 data for %s." % state.name
+ print "Downloading %s to %s..." % (url, tmpfile)
+
+ try:
+ # This can fail for a bunch of reasons...
+ urllib.urlretrieve(url, tmpfile)
+ print "Unzipping %s to %s..." % (tmpfile, state.sf1_data_path())
+ z = zipfile.ZipFile(tmpfile)
+ z.extractall(state.sf1_data_path())
+ except:
+ # That we don't care about.
+ pass
+ finally:
+ # But we always clean up after ourselves.
+ print "Removing %s..." % tmpfile
+ FileUtils.rm_f(tmpfile)
+ print "Done.\n"
+
+
+
+def download_blocks(states):
+ """
+ Download the TIGER/Line block files for each state.
+ """
+
+ for state in states:
+ # First, create the blocks data path if it doesn't exist.
+ FileUtils.mkdir_p(state.blocks_data_path(), 0755)
+
+ if not os.path.exists(state.blocks_shapefile_path()):
+ url = state.blocks_data_url()
+ tmpfile = state.blocks_zipfile_name()
+ print "Grabbing TIGER blocks data for %s." % state.name
+ print "Downloading %s to %s..." % (url, tmpfile)
+
+ try:
+ # This can fail for a bunch of reasons...
+ urllib.urlretrieve(url, tmpfile)
+ print "Unzipping %s to %s..." % (tmpfile, state.blocks_data_path())
+ z = zipfile.ZipFile(tmpfile)
+ z.extractall(state.blocks_data_path())
+ except:
+ # That we don't care about.
+ pass
+ finally:
+ # But we always clean up after ourselves.
+ print "Removing %s..." % tmpfile
+ FileUtils.rm_f(tmpfile)
+ print "Done.\n"
+
+
+