From 33c6eabf827209112b8b7a50584273c4ce49c184 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Wed, 14 Jul 2010 15:56:48 -0400 Subject: [PATCH] Google: add --snippet option to lucky command, which shows the text snippet for the page. --- plugins/Google/plugin.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index 59660fc69..734a7b862 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -163,18 +163,27 @@ class Google(callbacks.PluginRegexp): return format('; '.join(results)) @internationalizeDocstring - def lucky(self, irc, msg, args, text): - """ + def lucky(self, irc, msg, args, opts, text): + """[--snippet] Does a google search, but only returns the first result. + If option --snippet is given, returns also the page text snippet. """ + opts = dict(opts) data = self.search(text, msg.args[0], {'smallsearch': True}) if data['responseData']['results']: url = data['responseData']['results'][0]['unescapedUrl'] - irc.reply(url.encode('utf-8')) + if opts.has_key('snippet'): + snippet = " | " + data['responseData']['results'][0]['content'] + snippet = snippet.replace('', '') + snippet = snippet.replace('', '') + else: + snippet = "" + result = url + snippet + irc.reply(result.encode('utf-8')) else: irc.reply(_('Google found nothing.')) - lucky = wrap(lucky, ['text']) + lucky = wrap(lucky, [getopts({'snippet':'',}), 'text']) @internationalizeDocstring def google(self, irc, msg, args, optlist, text):