Skip to content

Instantly share code, notes, and snippets.

@scott2b
Last active April 19, 2018 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scott2b/2b25192c6afe37bbe1d782ed094ad06e to your computer and use it in GitHub Desktop.
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
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