Skip to content

Instantly share code, notes, and snippets.

@tombasche
Created February 20, 2019 21:23
Show Gist options
  • Save tombasche/9ed3d7163f4e05c544978d2668cede74 to your computer and use it in GitHub Desktop.
Save tombasche/9ed3d7163f4e05c544978d2668cede74 to your computer and use it in GitHub Desktop.
Download a file and extract it
def download_file(file_location, output_filename='file.json'):
handle = urlopen(file_location)
with open('temp.gz', 'wb') as out:
while True:
data = handle.read(1024)
if len(data) == 0:
break
out.write(data)
handle = gzip.open('temp.gz')
with open(output_filename, 'w') as out:
for line in handle:
out.write(line.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment