Last active
December 22, 2016 00:21
-
-
Save aausch/ebe82d33ab997c69312aeab478f9758d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import boto3 | |
import gzip | |
import io | |
import sys | |
import tempfile | |
BUCKET = 'SOME_BUCKET' | |
PATH = 'SOME_PATH' | |
# also see http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html - 'compression' setting | |
def iterate_gz_file(filename='file_name'): | |
s3 = boto3.resource('s3') | |
with tempfile.NamedTemporaryFile() as tmp_file: | |
s3.meta.client.download_file(LOG_BUCKET, '%s/%s' % (LOG_PATH, filename) , tmp_file.name) | |
with io.TextIOWrapper(io.BufferedReader(gzip.open(tmp_file.name))) as file: | |
for line in file: | |
print(line) | |
if __name__ == '__main__': | |
iterate_gz_file() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment