From cd73dfbc5210d33510228f0bdb2530659eb6bd51 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 16 Apr 2003 07:07:39 +0000 Subject: [PATCH] Changed formatting in presence of lacking titles and made it respond with as many results as it can. --- plugins/Google.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/Google.py b/plugins/Google.py index a1c7b1629..114bc7f18 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -44,6 +44,7 @@ Commands include: from baseplugin import * import time +import operator import google @@ -81,14 +82,20 @@ class Google(callbacks.Privmsg): def formatData(self, data): self._searched(data) time = '(search took %s seconds)' % data.meta.searchTime - results = data.results[:3] - results = ['\x02%s\x02: %s' % \ - (utils.htmlToText(r.title.encode('utf-8')), r.URL) \ - for r in results] + results = [] + for result in data.results: + title = utils.htmlToText(result.title.encode('utf-8')) + url = result.URL + if title: + results.append('\x02%s\x02: %s' % (title, url)) + else: + results.append(url) + while reduce(operator.add, map((4).__add__,map(len, results)),0) > 400: + results.pop() if not results: return 'No matches found %s' % time else: - return '%s %s' % (' ;; '.join(results), time) + return '%s %s' % (' :: '.join(results), time) def googlelicensekey(self, irc, msg, args): """ @@ -102,7 +109,11 @@ class Google(callbacks.Privmsg): googlelicensekey = privmsgs.checkCapability(googlelicensekey, 'admin') def google(self, irc, msg, args): - "" + """ + + Searches google.com for the given string. As many results as can fit + are included. + """ searchString = privmsgs.getArgs(args) data = google.doGoogleSearch(searchString, language='lang_en',