17 _urlopen = urllib.request.urlopen
22 _urlopen = urllib2.urlopen
23 _quote = urllib2.quote
27 _urlopen = urllib.urlopen
28 _quote = urllib2.quote
34 import xml.dom.minidom
38 MapQuestKey =
'Fmjtd%7Cluub296r2g%2Crl%3Do5-968shf'
39 MAPQUEST =
"http://open.mapquestapi.com/geocoding/v1/address"
55 return self.
_info[
'county'] < other._info[
'county']
61 for k
in self._info.keys():
62 data.append(pattern % (k, self.
_info[k]))
63 return ', '.join(data)
85 if loc.find(
'UK') < 0: loc =
'%s%s' % (loc,
',UK')
87 doc = xml.dom.minidom.parseString(data)
88 locations = doc.getElementsByTagName(
'locations')
89 locs = locations[0].getElementsByTagName(
'location')
91 name = loc.getElementsByTagName(
'adminArea5')[0].firstChild.data
92 county = loc.getElementsByTagName(
'adminArea4')[0].firstChild.data
93 lat = loc.getElementsByTagName(
'lat')[0].firstChild.data
94 lon = loc.getElementsByTagName(
'lng')[0].firstChild.data
95 info = {
'name': name,
'county': county,
'lat': lat,
'lon': lon}
97 self._places.append(place)
104 url =
'%s?location=%s&outFormat=xml&key=%s'
105 fullurl = url % (MAPQUEST, _quote(location), MapQuestKey)
106 data = _urlopen(fullurl).read()
109 def _getPlaces(self):
113 data = [s.__repr__()
for s
in self.
_places]
114 return '\n'.join(data)
116 places = property(_getPlaces)