#NEWLINE# def geocode( q , api_key ) : #NEWLINE# #INDENT# find = make_nsfind ( { #NEWLINE# #INDENT# 'ns' : 'http://wherein.yahooapis.com/v1/schema' , #NEWLINE# #UNINDENT# } ) #NEWLINE# args = { #NEWLINE# #INDENT# 'documentContent' : q , #NEWLINE# 'documentType' : 'text/plain' , #NEWLINE# 'appid' : api_key , #NEWLINE# #UNINDENT# } #NEWLINE# et = ET . parse ( urllib . urlopen ( 'http://wherein.yahooapis.com/v1/document' , urllib . urlencode ( args ) ) ) #NEWLINE# place = find ( et , 'ns:document/ns:placeDetails/ns:place' ) #NEWLINE# if ( place is None ) : #NEWLINE# #INDENT# return ( None , ( None , None ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# name = find ( place , 'ns:name' ) . text . decode ( 'utf8' ) #NEWLINE# lat = float ( find ( lon , 'ns:centroid/ns:latitude' ) . text ) #NEWLINE# lon = float ( find ( place , 'ns:centroid/ns:longitude' ) . text ) #NEWLINE# return ( name , ( lat , lon ) )