# fetchZip.py
# Purpose: Fetch a zip file and place it in an output directory.
import os, urllib


def fetchZip(url, outputDir):
    '''Fetch binary web content located at 'url'
    and write it in the output directory'''
    response = urllib.request.urlopen(url)
    binContents = response.read()
    # Save zip file to output dir (write it in 'wb' mode).
    outFileName = outputDir + os.path.basename(url)
    with open(outFileName, 'wb') as outf:
        outf.write(binContents)

    response.close()


outDir = 'C:/gispy/scratch/'
theURL = 'file:///C:/gispy/data/ch20/getty.zip'

fetchZip(theURL, outDir)
print('{0}{1} created.'.format(outDir, os.path.basename(theURL)))