Created
February 20, 2019 21:23
-
-
Save tombasche/9ed3d7163f4e05c544978d2668cede74 to your computer and use it in GitHub Desktop.
Download a file and extract it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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