Created
December 6, 2012 22:13
-
-
Save conradlee/4228973 to your computer and use it in GitHub Desktop.
Photo csv parser
This file contains 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 | |
import gzip | |
from contextlib import closing | |
def photo_tup_generator(in_filename, bb_left, bb_right, bb_bottom, bb_top): | |
""" | |
Note: rows yielded are in utf8 (have not been decoded to unicode) | |
""" | |
with closing(gzip.open(in_filename, mode="rb", compresslevel=6)) as f: | |
reader = csv.reader(f, escapechar='\\', doublequote=True, quotechar='"', quoting=csv.QUOTE_MINIMAL) | |
for row in reader: | |
if (len(row) == 12) and (row[1][-4] == "@"): | |
photo_id, owner_id, datetaken, datetaken_granularity, date_upload, lat, lon, accuracy, tags, title, desc, views = row | |
if lat and lon: | |
lat = float(lat) | |
lon = float(lon) | |
if lat > bb_bottom and lat <= bb_top: | |
if lon> bb_left and lon < bb_right: | |
yield row |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment