예제 #1
0
    def response(self, nick, args, kwargs):
        try:
            for matches, responses in self.data:
                for match in matches:
                    if match.search(args[0]):
                        result = self.parseTokens(random.choice(responses))
                        return encoding.convert(result)

        except Exception, error:
            self.log.warn(u'error in %s: %s' % (self.__module__, error))
            self.log.exception(error)
예제 #2
0
 def response(self, nick, args, kwargs):
     result = self.factoids.parse(args[0], nick, kwargs[u"req"])
     return encoding.convert(result)
예제 #3
0
파일: figlet.py 프로젝트: cjones/madcow
 def response(self, nick, args, kwargs):
     kwargs['req'].blockquoted = True
     figlet = pyfiglet.Figlet(zipfile=self.zipfile)
     figlet.set_font(font_name=random.choice(self.fonts))
     return encoding.convert(figlet.render_text(args[0]))
예제 #4
0
파일: figlet.py 프로젝트: seunboi4u/madcow
 def response(self, nick, args, kwargs):
     figlet = pyfiglet.Figlet(zipfile=self.zipfile)
     figlet.set_font(font_name=random.choice(self.fonts))
     return encoding.convert(figlet.render_text(args[0]))
예제 #5
0
 def response(self, nick, args, kwargs):
     result = self.factoids.parse(args[0], nick, kwargs[u'req'])
     return encoding.convert(result)
예제 #6
0
    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 = strip_html(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:
            self.log.exception(error)