Skip to content

Instantly share code, notes, and snippets.

@emilepetrone
Created October 11, 2011 20:31
Show Gist options
  • Save emilepetrone/1279328 to your computer and use it in GitHub Desktop.
Save emilepetrone/1279328 to your computer and use it in GitHub Desktop.
import xlrd
from simplegeo import Client, json, APIError
from multiprocessing import Pool
def f(z):
z = str(z)
try:
# z = str(10001)
results = client.context.get_context_by_address(z)
for b in results["features"]:
if b["classifiers"][0]["category"] == 'Neighborhood':
n = b["name"]
print n
neighborhoods.append(n)
except APIError:
errors.append(z)
print 'Neighborhoods: '
print neighborhoods
print 'Errors: '
print errors
if __name__ == '__main__':
row = 1
neighborhoods = []
zipcodes = []
errors = []
book = xlrd.open_workbook("zipcodes.xls")
sheet = book.sheet_by_index(0)
rows = sheet.nrows
client = Client('SbAc87cM7EK2qCvmjymQtXU66MdXGNPr','CNmJaCEGGY3V7Tq3NEJsvNJCdJZjvgfN')
while row <= 60000:
current_row = sheet.row(row)[0]
zip = sheet.cell_value(row,0)
zip = int(zip)
print zip
row += 1
if not zip in zipcodes:
zipcodes.append(zip)
z = str(zip)
z.zfill(5)
print 'Yep'
print zipcodes
pool = Pool(processes=4)
result = pool.apply_async(f,zipcodes)
print result.get(timeout=1)
print pool.map(f, zipcodes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment