Example #1
0
 def lookup(self, term, idx=1):
     """Lookup term in dictionary"""
     url = urljoin(self.define_url, quote(term.lower()))
     soup = getsoup(url, referer=self.base_url)
     for br in soup('br'):
         br.extract()
     val = stripHTML(soup.renderContents().decode('utf-8'))
     val = val.replace(u'\xa0', ' ').replace('\n', ' ')
     return self.whitespace_re.sub(' ', val).strip()
Example #2
0
 def response(self, nick, args, kwargs):
     try:
         soup = getsoup(self.url, {'InData': args[0]})
         city = soup.body.find('table', bgcolor='#ffffcc').a
         return u'%s: %s: %s, %s' % (
                 nick, args[0], proper(render(city).capitalize()),
                 proper(render(city.parent.findNext('td'))))
         return u''
     except Exception, error:
         log.warn(u'error in module %s' % self.__module__)
         log.exception(error)
         return u"%s: I couldn't look that up for some reason.  D:" % nick
Example #3
0
 def response(self, nick, args, kwargs):
     try:
         soup = getsoup(self.spec_url % int(args[0]) if args[0] else self.rand_url)
         soup.find('div', id='submit').extract()
         post = soup.body.find('div', 'post')
         return u'%s: (%d) %s' % (nick, int(post.find('a', 'fmllink')['href'].split('/')[-1]),
                                  stripHTML(' '.join(link.renderContents()
                                                     for link in post('a', 'fmllink')).decode('utf-8', 'ignore')))
     except Exception, error:
         log.warn(u'error in module %s' % self.__module__)
         log.exception(error)
         return u'%s: Today I couldn\'t seem to access fmylife.com.. FML' % nick
Example #4
0
 def lookup(self, query, idx=None):
     """Look up term on urban dictionary"""
     if idx is None:
         idx = 1
     orig_idx = idx
     page = int(idx / self.RESULTS_PER_PAGE)
     idx = (idx % self.RESULTS_PER_PAGE) - 1
     if idx == -1:
         idx = 6
     soup = getsoup(self.urban_search, {'term': query, 'page': page},
                    referer=self.urban_url)
     return self.parse(soup, idx, page, orig_idx)
Example #5
0
 def response(self, nick, args, kwargs):
     try:
         opts = {'hl': 'en', 'aq': 'f', 'safe': 'off', 'q': args[0]}
         soup = getsoup(self.google_search, opts, referer=self.google_url)
         a = soup.body.find('a', 'spell')
         if a:
             res = stripHTML(a.renderContents().decode('utf-8', 'ignore'))
         else:
             res = u'spelled correctly'
     except Exception, error:
         log.warn('error in module %s' % self.__module__)
         log.exception(error)
         res = u'I had trouble with that'
Example #6
0
 def response(self, nick, args, kwargs):
     try:
         try:
             url = self.google.lucky(u'site:lyrics.wikia.com ' + args[0])
         except NonRedirectResponse:
             opts = {'search': args[0], 'ns0': 1}
             soup = getsoup(self.searchurl, referer=self.baseurl, opts=opts)
             url = urljoin(self.baseurl, soup.li.a['href'])
         soup = getsoup(url, referer=self.baseurl)
         title = self.render(soup.title).split(' - LyricWiki')[0]
         title = title.replace(':', ' - ')
         title = title.replace('_', ' ')
         lyrics = soup.find('div', 'lyricbox')
         for spam in lyrics('div', 'rtMatcher'):
             spam.extract()
         lyrics = self.render(lyrics)
         lyrics = self.normalize(lyrics)
         if not lyrics or lyrics == 'None':
             raise ValueError('no results')
         return u'%s:\n%s' % (title, lyrics)
     except Exception, error:
         log.warn('error in module %s' % self.__module__)
         log.exception(error)
         return u'%s: %s' % (nick, "Couldn't find them, they must suck")
Example #7
0
    def lookup_verse(self, query, book=None):
        """Lookup specified verse"""
        if book is None:
            book = self.DEFAULT_BIBLE
        elif book not in self.bibles:
            return u'Unknown bible.. why do you hate god so much?'
        opts = {'search': query, 'version': book}
        soup = getsoup(self.bg_search, opts, referer=self.bg_search)
        res = soup.body.find('div', 'result-text-style-normal')
        res = res.renderContents().decode('utf-8', 'ignore')

        # convert superscript verse markers to unicode
        while True:
            match = self.sup_re.search(res)
            if not match:
                break
            res = res.replace(match.group(0),
                              superscript(match.group(1)))

        return stripHTML(res).strip()
Example #8
0
 def random(self):
     """Get a random definition"""
     soup = getsoup(self.urban_random, referer=self.urban_url)
     return self.parse(soup)