mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added bold and maximum-results configurable.
This commit is contained in:
parent
83995296b7
commit
2f55345012
@ -1,4 +1,4 @@
|
|||||||
#re!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
###
|
###
|
||||||
# Copyright (c) 2002, Jeremiah Fincher
|
# Copyright (c) 2002, Jeremiah Fincher
|
||||||
@ -142,7 +142,12 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
('search-snarfer', configurable.BoolType, False,
|
('search-snarfer', configurable.BoolType, False,
|
||||||
"""Determines whether the search snarfer is enabled. If so, messages
|
"""Determines whether the search snarfer is enabled. If so, messages
|
||||||
(even unaddressed ones) beginning with the word 'google' will result
|
(even unaddressed ones) beginning with the word 'google' will result
|
||||||
in the first URL Google returns being sent to the channel.""")]
|
in the first URL Google returns being sent to the channel."""),
|
||||||
|
('bold', configurable.BoolType, True,
|
||||||
|
"""Determines whether results are bolded."""),
|
||||||
|
('maximum-results', configurable.PositiveIntType, 10,
|
||||||
|
"""Determines the maximum number of results returned from the
|
||||||
|
google command."""),]
|
||||||
)
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
configurable.Mixin.__init__(self)
|
||||||
@ -155,16 +160,20 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
configurable.Mixin.die(self)
|
configurable.Mixin.die(self)
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
|
||||||
def formatData(self, data):
|
def formatData(self, data, bold=True, max=0):
|
||||||
if isinstance(data, basestring):
|
if isinstance(data, basestring):
|
||||||
return data
|
return data
|
||||||
time = 'Search took %s seconds' % data.meta.searchTime
|
time = 'Search took %s seconds' % data.meta.searchTime
|
||||||
results = []
|
results = []
|
||||||
|
if max:
|
||||||
|
data.results = data.results[:max]
|
||||||
for result in data.results:
|
for result in data.results:
|
||||||
title = utils.htmlToText(result.title.encode('utf-8'))
|
title = utils.htmlToText(result.title.encode('utf-8'))
|
||||||
url = result.URL
|
url = result.URL
|
||||||
if title:
|
if title:
|
||||||
results.append('%s: <%s>' % (ircutils.bold(title), url))
|
if bold:
|
||||||
|
title = ircutils.bold(title)
|
||||||
|
results.append('%s: <%s>' % (title, url))
|
||||||
else:
|
else:
|
||||||
results.append(url)
|
results.append(url)
|
||||||
if not results:
|
if not results:
|
||||||
@ -207,7 +216,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
kwargs[option[2:]] = argument
|
kwargs[option[2:]] = argument
|
||||||
searchString = privmsgs.getArgs(rest)
|
searchString = privmsgs.getArgs(rest)
|
||||||
data = search(self.log, searchString, **kwargs)
|
data = search(self.log, searchString, **kwargs)
|
||||||
irc.reply(msg, self.formatData(data))
|
bold = self.configurables.get('bold', msg.args[0])
|
||||||
|
max = self.configurables.get('maximum-results', msg.args[0])
|
||||||
|
irc.reply(msg, self.formatData(data, bold=bold, max=max))
|
||||||
|
|
||||||
def metagoogle(self, irc, msg, args):
|
def metagoogle(self, irc, msg, args):
|
||||||
"""<search> [--(language,restrict)=<value>] [--{similar,notsafe}]
|
"""<search> [--(language,restrict)=<value>] [--{similar,notsafe}]
|
||||||
|
@ -33,44 +33,46 @@ from testsupport import *
|
|||||||
|
|
||||||
class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Google',)
|
plugins = ('Google',)
|
||||||
def testNoNoLicenseKeyError(self):
|
if network:
|
||||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
def testNoNoLicenseKeyError(self):
|
||||||
self.assertNoResponse(' ')
|
self.assertNotError('google config groups-snarfer on')
|
||||||
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
||||||
|
self.assertNoResponse(' ')
|
||||||
|
|
||||||
def testGroupsSnarfer(self):
|
def testGroupsSnarfer(self):
|
||||||
self.assertNotError('google config groups-snarfer on')
|
self.assertNotError('google config groups-snarfer on')
|
||||||
self.assertRegexp('http://groups.google.com/groups?dq=&hl=en&'
|
self.assertRegexp('http://groups.google.com/groups?dq=&hl=en&'
|
||||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
|
||||||
'0310132012.738e22fc%40posting.google.com',
|
|
||||||
r'comp\.lang\.python.*question: usage of __slots__')
|
|
||||||
self.assertRegexp('http://groups.google.com/groups?selm=ExDm.'
|
|
||||||
'8bj.23%40gated-at.bofh.it&oe=UTF-8&output=gplain',
|
|
||||||
r'linux\.kernel.*NFS client freezes')
|
|
||||||
self.assertRegexp('http://groups.google.com/groups?'
|
|
||||||
'q=kernel+hot-pants&hl=en&lr=&ie=UTF-8&oe=UTF-8&'
|
|
||||||
'selm=1.5.4.32.19970313170853.00674d60%40'
|
|
||||||
'adan.kingston.net&rnum=1',
|
|
||||||
r'Madrid Bluegrass Ramble')
|
|
||||||
self.assertRegexp('http://groups.google.com/groups?'
|
|
||||||
'selm=1.5.4.32.19970313170853.00674d60%40adan.'
|
|
||||||
'kingston.net&oe=UTF-8&output=gplain',
|
|
||||||
r'Madrid Bluegrass Ramble')
|
|
||||||
self.assertRegexp('http://groups.google.com/groups?'
|
|
||||||
'dq=&hl=en&lr=&ie=UTF-8&threadm=mailman.1010.'
|
|
||||||
'1069645289.702.python-list%40python.org'
|
|
||||||
'&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8'
|
|
||||||
'%26group%3Dcomp.lang.python',
|
|
||||||
r'comp\.lang\.python.*What exactly are bound')
|
|
||||||
|
|
||||||
def testConfig(self):
|
|
||||||
self.assertNotError('google config groups-snarfer off')
|
|
||||||
self.assertNoResponse('http://groups.google.com/groups?dq=&hl=en&'
|
|
||||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||||
'0310132012.738e22fc%40posting.google.com')
|
'0310132012.738e22fc%40posting.google.com',
|
||||||
self.assertNotError('google config groups-snarfer on')
|
r'comp\.lang\.python.*question: usage of __slots__')
|
||||||
self.assertNotError('http://groups.google.com/groups?dq=&hl=en&'
|
self.assertRegexp('http://groups.google.com/groups?selm=ExDm.'
|
||||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
'8bj.23%40gated-at.bofh.it&oe=UTF-8&output=gplain',
|
||||||
'0310132012.738e22fc%40posting.google.com')
|
r'linux\.kernel.*NFS client freezes')
|
||||||
|
self.assertRegexp('http://groups.google.com/groups?'
|
||||||
|
'q=kernel+hot-pants&hl=en&lr=&ie=UTF-8&oe=UTF-8&'
|
||||||
|
'selm=1.5.4.32.19970313170853.00674d60%40'
|
||||||
|
'adan.kingston.net&rnum=1',
|
||||||
|
r'Madrid Bluegrass Ramble')
|
||||||
|
self.assertRegexp('http://groups.google.com/groups?'
|
||||||
|
'selm=1.5.4.32.19970313170853.00674d60%40adan.'
|
||||||
|
'kingston.net&oe=UTF-8&output=gplain',
|
||||||
|
r'Madrid Bluegrass Ramble')
|
||||||
|
self.assertRegexp('http://groups.google.com/groups?'
|
||||||
|
'dq=&hl=en&lr=&ie=UTF-8&threadm=mailman.1010.'
|
||||||
|
'1069645289.702.python-list%40python.org'
|
||||||
|
'&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8'
|
||||||
|
'%26group%3Dcomp.lang.python',
|
||||||
|
r'comp\.lang\.python.*What exactly are bound')
|
||||||
|
|
||||||
|
def testConfig(self):
|
||||||
|
self.assertNotError('google config groups-snarfer off')
|
||||||
|
self.assertNoResponse('http://groups.google.com/groups?dq=&hl=en&'
|
||||||
|
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||||
|
'0310132012.738e22fc%40posting.google.com')
|
||||||
|
self.assertNotError('google config groups-snarfer on')
|
||||||
|
self.assertNotError('http://groups.google.com/groups?dq=&hl=en&'
|
||||||
|
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||||
|
'0310132012.738e22fc%40posting.google.com')
|
||||||
|
|
||||||
def testInvalidKeyCaught(self):
|
def testInvalidKeyCaught(self):
|
||||||
self.assertNotError(
|
self.assertNotError(
|
||||||
|
Loading…
Reference in New Issue
Block a user