mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Google: add --snippet option to lucky command, which shows the text snippet for the page.
This commit is contained in:
parent
edc4d8644e
commit
6905d22c2c
@ -159,18 +159,27 @@ class Google(callbacks.PluginRegexp):
|
||||
else:
|
||||
return format('; '.join(results))
|
||||
|
||||
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'])
|
||||
|
||||
def google(self, irc, msg, args, optlist, text):
|
||||
"""<search> [--{filter,language} <value>]
|
||||
|
Loading…
Reference in New Issue
Block a user