コード例 #1
0
ファイル: artfart.py プロジェクト: gipi/Richie
    random_url = urljoin(baseurl, 'random.cgi')
    artfart = re.compile(
        r'<h1>#<a href="\S+.html">\d+</a>: (.*?)</h1>.*?<pre>(.*?)</pre>',
        re.DOTALL)

    def response(self, nick, args, kwargs):
        query = args[0]
        if query is None or query == '':
            url = self.random_url
        else:
            query = ' '.join(query.split())
            query = query.replace(' ', '_')
            query = urllib.quote(query) + '.html'
            url = urljoin(self.baseurl, query)
        try:
            doc = geturl(url)
            results = self.artfart.findall(doc)
            result = random.choice(results)
            title, art = result
            art = stripHTML(art)
            return '>>> %s <<<\n%s' % (title, art)
        except Exception, e:
            log.warn('error in %s: %s' % (self.__module__, e))
            log.exception(e)
            return "%s: I had a problem with that, sorry." % nick


if __name__ == '__main__':
    from include.utils import test_module
    test_module(Main)
コード例 #2
0
ファイル: chp.py プロジェクト: compbrain/madcow
    clean = re.compile(u'[^0-9a-z ]', re.I)

    def response(self, nick, args, kwargs):
        query = args[0]
        try:
            check = self.clean.sub(u'', query)
            check = re.compile(check, re.I)
            results = []
            doc = geturl(self.url)
            for i in self.incidents.findall(doc):
                data = [stripHTML(c) for c in self.data.findall(i)][1:]
                if len(data) != 4:
                    continue
                if check.search(data[2]):
                    results.append(u'=> %s: %s - %s - %s' % (data[0], data[1],
                                                             data[2], data[3]))

            if len(results) > 0:
                return u'\n'.join(results)
            else:
                return u'%s: No incidents found' % nick
        except Exception, error:
            log.warn(u'error in module %s' % self.__module__)
            log.exception(error)
            return u'%s: I failed to perform that lookup' % nick


if __name__ == u'__main__':
    from include.utils import test_module
    test_module(Main)