class WeatherSaxHandler(object): w={} def start_element(self, name, attrs): if name=='yweather:location': self.w['city']=attrs['city'] self.w['country']=attrs['country'] if name=='yweather:forecast': if not 'today' in self.w: self.w['today']={} self.w['today']['text']=attrs['text'] self.w['today']['low']=int(attrs['low']) self.w['today']['high']=int(attrs['high']) elif not 'tomorrow' in self.w: self.w['tomorrow']={} self.w['tomorrow']['text']=attrs['text'] self.w['tomorrow']['low']=int(attrs['low']) self.w['tomorrow']['high']=int(attrs['high']) def parse_weather(xml): handler=WeatherSaxHandler() parser = ParserCreate() parser.StartElementHandler = handler.start_element parser.Parse(data) return handler.w
Sign in to make a reply
Yoz_Hollow