<s> from utils import make_nsfind , ET , geocoder_factory <EOL> import urllib <EOL> def geocode ( q , api_key ) : <EOL> find = make_nsfind ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> args = { '<STR_LIT:location>' : q , '<STR_LIT>' : api_key } <EOL> url = '<STR_LIT>' % urllib . urlencode ( args ) <EOL> et = ET . parse ( urllib . urlopen ( url ) ) <EOL> result = find ( et , '<STR_LIT>' ) <EOL> if not result : <EOL> return ( None , ( None , None ) ) <EOL> else : <EOL> namebits = { } <EOL> for field in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> bit = find ( result , '<STR_LIT>' % field ) <EOL> if bit is not None and bit . text : <EOL> namebits [ field ] = bit . text . decode ( '<STR_LIT:utf8>' ) <EOL> if '<STR_LIT>' in namebits : <EOL> name = '<STR_LIT>' % namebits <EOL> elif '<STR_LIT>' in namebits : <EOL> name = '<STR_LIT>' % namebits <EOL> elif '<STR_LIT>' in namebits : <EOL> name = '<STR_LIT>' % namebits <EOL> elif '<STR_LIT>' in namebits : <EOL> name = '<STR_LIT>' % namebits <EOL> elif '<STR_LIT>' in namebits : <EOL> name = namebits [ '<STR_LIT>' ] <EOL> else : <EOL> return ( None , ( None , None ) ) <EOL> lat = float ( find ( result , '<STR_LIT>' ) . text ) <EOL> lon = float ( find ( result , '<STR_LIT>' ) . text ) <EOL> return ( name , ( lat , lon ) ) <EOL> geocoder = geocoder_factory ( geocode ) </s>
