Last active
April 19, 2018 02:42
-
-
Save scott2b/2b25192c6afe37bbe1d782ed094ad06e to your computer and use it in GitHub Desktop.
Download and process a zipped csv file without saving to a tmp file
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
import csv | |
from io import BytesIO, TextIOWrapper | |
from urllib import request | |
from zipfile import ZipFile | |
url = 'http://data.gdeltproject.org/gdeltv2/20180419011500.gkg.csv.zip' | |
with ZipFile(BytesIO(request.urlopen(url).read())) as zf: | |
f = zf.namelist()[0] | |
with zf.open(f, 'r') as csvfile: | |
reader = csv.reader(TextIOWrapper(csvfile), delimiter='\t') | |
for row in reader: | |
print(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment