Exemplo n.º 1
0
    def doGoogleSearch(self, user, query, start, max):
        """Perform Google search"""

        self.lastSearchStart += max

        s = GoogleSearch(self.options.proxy, self.options.key)
        result = s.search(query.decode('utf-8'), start, max)

        if result:      
            results = result.getResultElements()
            count = 0
            msg = 'Results: '

            for entry in results:
                title = htmlToText(entry.title.encode('utf-8'))
                url = entry.URL
                new = ' %s %s: <%s> |' % (msg, bold(title), url)
              
                if len(new) > 430:
                    msg = msg[:-1]
                    self.lastSearchStart -= count 
                    break
                else:
                    msg = new
                    count+= 1

            if msg[-1] == '|':
                msg = msg[:-1]

            msg += ' (search took %s seconds)' % (str(result.getSearchTime())[:6],)

            self.msg(user, msg.strip())
        else:
            self.msg(user, 'No Results')
Exemplo n.º 2
0
 def cmd_suggest(self, user, channel, params):
     """Use google spell suggestion service to suggest a spelling. Usage: SUGGEST <word>"""
     if len(params) == 1:
         s = GoogleSearch(self.options.proxy, self.options.key)
         result = s.spell(params[0])
         self.msg(user, 'Suggestion(s): %s' % (result, ))
     else:
         self.msg(user, 'ERROR: No Parameters Given')