Created
August 8, 2012 21:42
-
-
Save no-reply/3299038 to your computer and use it in GitHub Desktop.
get county from melissadata
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
#! /usr/bin/python2 | |
''' Takes an address as args and prints the county from MelissaData.com | |
Usage: | |
./county.py 1234 Fake Street, Sometown, CA 12345 | |
Works with quotes, too: | |
./county.py "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 = "http://www.melissadata.com/lookups/AddressCheck.asp?" + urllib.urlencode({"InData": address}) | |
html = urllib2.urlopen(queryurl).read() | |
if "Address Verified" in html: | |
cindex = html.index('County') | |
print re.search('<b>(.*)</b>', html[cindex:cindex + 40]).group(1).capitalize() | |
else: | |
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