mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Google: add --snippet option to lucky command, which shows the text snippet for the page.
This commit is contained in:
parent
5395000e76
commit
33c6eabf82
@ -163,18 +163,27 @@ class Google(callbacks.PluginRegexp):
|
||||
return format('; '.join(results))
|
||||
|
||||
@internationalizeDocstring
|
||||
def lucky(self, irc, msg, args, text):
|
||||
"""<search>
|
||||
def lucky(self, irc, msg, args, opts, text):
|
||||
"""[--snippet] <search>
|
||||
|
||||
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('<b>', '')
|
||||
snippet = snippet.replace('</b>', '')
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user