def war(self): try: rss = feedparser.parse(self._war_url) return rss.entries[0].title except Exception, error: log.warn(u'error in module %s' % self.__module__) log.exception(error) return u'UNKNOWN'
def response(self, nick, args, kwargs): try: item = feedparser.parse(self.url).entries[0] body = stripHTML(item.description).strip() return u' | '.join([item.link, body, item.updated]) except Exception, error: log.warn(u'error in module %s' % self.__module__) log.exception(error) return u'%s: %s' % (nick, error)
def response(self, nick, args, kwargs): query = args[0] try: if not query or query == u'headline': url = self._world_url else: url = self._search_url + urllib.quote(query.encode('utf-8')) item = feedparser.parse(url).entries[0] return u' | '.join([item.link, item.description, item.updated]) except Exception, error: log.warn(u'error in module %s' % self.__module__) log.exception(error) return u'%s: %s' % (nick, self._error)
def response(self, nick, args, kwargs): try: rss = feedparser.parse(self.url) entry = rss.entries[3] title, summary, link = map( stripHTML, [entry.title, entry.summary, entry.link]) summary = self.break_re.sub(u' ', summary) if len(summary) > self.max: summary = summary[:self.max - 4] + u' ...' return u'%s [%s] %s' % (title, link, summary) except Exception, error: log.warn(u'error in module %s' % self.__module__) log.exception(error) return u'%s: error reading woot page' % nick
def forecast(self, location): page = geturl(url=self.search, opts={u'query': location}, referer=self.baseurl) soup = BeautifulSoup(page) # disambiguation page if u'Search Results' in unicode(soup): table = soup.find(u'table', attrs={u'class': u'dataTable'}) tbody = soup.find(u'tbody') results = [row.findAll(u'td')[0].find(u'a') for row in tbody.findAll(u'tr')] results = [(normalize(unicode(result.contents[0])), urljoin(Weather.baseurl, unicode(result[u'href']))) for result in results] match = None for result in results: if result[0] == normalize(location): match = result[1] break if match is None: match = results[0][1] page = geturl(url=match, referer=self.search) soup = BeautifulSoup(page) title = soup.find(u'h1').string.strip() rss_url = soup.find(u'link', attrs=self._rss_link)[u'href'] rss = feedparser.parse(rss_url) conditions = rss.entries[0].description # XXX ok, here's the deal. this page has raw utf-8 bytes encoded # as html entities, and in some cases latin1. this demonstrates a # total misunderstanding of how unicode works on the part of the # authors, so we need to jump through some hoops to make it work conditions = conditions.encode(u'raw-unicode-escape') conditions = stripHTML(conditions) conditions = encoding.convert(conditions) fields = self._bar.split(conditions) data = {} for field in fields: try: key, val = self._keyval.search(field).groups() data[key] = val except: pass try: temp = float(self._tempF.search(data[u'Temperature']).group(1)) blink = False if temp < 0: color = u'magenta' elif temp >=0 and temp < 40: color = u'blue' elif temp >= 40 and temp < 60: color = u'cyan' elif temp >= 60 and temp < 80: color = u'green' elif temp >= 80 and temp < 90: color = u'yellow' elif temp >= 90 and temp < 100: color = u'red' elif temp >= 100: color = u'red' blink = True data[u'Temperature'] = self.colorlib.get_color(color, text=data[u'Temperature']) # XXX this seems ill-conceived if blink: data[u'Temperature'] = u'\x1b[5m' + data[u'Temperature'] + \ u'\x1b[0m' except Exception, error: log.exception(error)