def CreateConfig(): root = ET.Element("root") doc = ET.SubElement(root, "General") x = geolocation.GetUTCOffset() ET.SubElement(doc, "UTCOffset", name='UTCOffset').text = "%s" % x ET.SubElement(doc, "lat").text = geolocation.geocode("3 Galileo Street, Gregory Hills, New South Wales")['lat'] ET.SubElement(doc, "lng").text = geolocation.geocode("3 Galileo Street, Gregory Hills, New South Wales")['lng'] tree = ET.ElementTree(root) print(tree) tree.write("Config.xml")
def clean(self): cleaned_data = self.cleaned_data if cleaned_data['method'] in ('html5', 'html5request', 'gears', 'manual', 'geocoded', 'other', 'favourite'): if cleaned_data['method'] == 'geocoded': results = geocode(cleaned_data['name']) if len(results) > 0: cleaned_data.update(results[0]) cleaned_data['longitude'], cleaned_data['latitude'] = cleaned_data['location'] # Ignore alternatives for postcodes if not re.match(POSTCODE_RE, cleaned_data['name'].upper()): cleaned_data['alternatives'] = results[1:] else: cleaned_data['alternatives'] = [] else: raise forms.ValidationError("Unable to find a location that matches '%s'." % cleaned_data['name']) for key in ('latitude', 'longitude', 'accuracy'): if cleaned_data.get(key) is None: self._errors[key] = ErrorList(['method requires that ' + key + ' must be specified']) if not self._errors: cleaned_data['location'] = cleaned_data['longitude'], cleaned_data['latitude'] if not cleaned_data.get('name'): try: cleaned_data['name'] = reverse_geocode( self.cleaned_data['longitude'], self.cleaned_data['latitude'])[0]['name'] except: cleaned_data['name'] = u"↝ %f, %f" % (self.cleaned_data['longitude'], self.cleaned_data['latitude']) elif cleaned_data['method'] in ('denied', 'error'): for key in ('latitude', 'longitude', 'accuracy'): if cleaned_data.get(key) is None: self._errors[key] = ErrorList(['method requires that ' + key + ' must be specified']) else: self._errors['method'] = ErrorList(['method is required']) return cleaned_data