Skip to content

Instantly share code, notes, and snippets.

Created Aug 8, 2012
What would you like to do?
get county from melissadata
#! /usr/bin/python2
''' Takes an address as args and prints the county from
./ 1234 Fake Street, Sometown, CA 12345
Works with quotes, too:
./ "1234 Fake Street, Sometown, CA 12345"
import sys
import re
import urllib
import urllib2
address = ''
for arg in sys.argv:
if not '.py' in arg:
address += arg
address += ' '
queryurl = "" + urllib.urlencode({"InData": address})
html = urllib2.urlopen(queryurl).read()
if "Address Verified" in html:
cindex = html.index('County')
print'<b>(.*)</b>', html[cindex:cindex + 40]).group(1).capitalize()
raise Exception("Melissa returned some kind of error.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment