Skip to content

Instantly share code, notes, and snippets.

@actongorton
Last active August 29, 2015 14:20
Show Gist options
  • Save actongorton/4382e52660ea90b6c038 to your computer and use it in GitHub Desktop.
Save actongorton/4382e52660ea90b6c038 to your computer and use it in GitHub Desktop.
Geocoding Gists
import csv
import time
from pygeocoder import Geocoder
# file to write to:
f = open('results.csv', 'a')
# separate instance to read the file / might just comment this and the if statement out if file does not yet exist
rf = open('results.csv', 'rb')
results_so_far = csv.reader(rf, delimiter=',', quotechar='"')
# create an array with the pin numbers found in results csv
# this is to pick up where last left off in the event of a program crash
results_array = []
for row in results_so_far:
results_array.append(row[0])
# file to open
with open('tax_liens.csv', 'rb') as csvfile:
needs_geocoding = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in needs_geocoding:
# skip the column header embedded in csv and check if record is already on file
if row[0] != 'X' and row[3] not in results_array:
print row[3]
print row[1] + ', ' + row[0]
x = float(row[1])
y = float(row[0])
print 'not found!'
# # IDE throws a fit about float for no reason / works just fine
results = Geocoder.reverse_geocode(x, y)
print results[0]
data = row[3] + ', "' + str(results[0]) + '"\n'
f.write(data)
# add a half second sleep timer to not anger Google
time.sleep(.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment