Created
October 13, 2013 02:08
-
-
Save thequbit/6957270 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def geocodemq(address): | |
key = "Fmjtd%7Cluub2gurll%2C8w%3Do5-9uagq4" | |
vals = {'location': address} | |
qstr = urllib.urlencode(vals) | |
#print "QSTR = '{0}'".format(qstr) | |
reqstr = "http://www.mapquestapi.com/geocoding/v1/address?key={0}&outFormat=json&maxResults=1&{1}".format(key,qstr) | |
#print "Sending: {0}".format(reqstr) | |
_json = simplejson.loads(urllib.urlopen(reqstr).read()) | |
return _json | |
def pulldatamq(_json): | |
print _json | |
fulladdress = "" | |
lat = "" | |
lng = "" | |
zipcode = "" | |
streetnumber = "" | |
route = "" | |
locality = "" | |
state = "" | |
country = "" | |
try: | |
#print _json['results'][0] | |
#treet = _json['results'][0]['locations'][0]['street'] | |
town = _json['results'][0]['locations'][0]['adminArea5'] | |
state = _json['results'][0]['locations'][0]['adminArea3'] | |
zipcode = _json['results'][0]['locations'][0]['postalCode'].split('-')[0] | |
fulladdress = ", {0}, {1}, {2}".format(town,state,zipcode) | |
lat = _json['results'][0]['locations'][0]['latLng']['lat'] | |
lng = _json['results'][0]['locations'][0]['latLng']['lng'] | |
route = _json['results'][0]['locations'][0]['street'].split(" ")[0] | |
route = "".join(_json['results'][0]['locations'][0]['street'].split(" ")[1:]) | |
locality = _json['results'][0]['locations'][0]['adminArea5'] | |
country = "US" | |
valid = True | |
except: | |
valid = False | |
retval = valid,fulladdress,lat,lng,zipcode,streetnumber,route,locality,state,country | |
print retval | |
return retval | |
#return fulladdress,lat,lng,zipcode, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment