Google: Remove calc and phonebook commands

Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
James McCoy 2012-09-05 23:04:10 -04:00
parent 304facd167
commit 6f925e5f7a
2 changed files with 0 additions and 66 deletions

View File

@ -242,54 +242,6 @@ class Google(callbacks.PluginRegexp):
irc.reply(url.encode('utf-8'), prefixNick=False) irc.reply(url.encode('utf-8'), prefixNick=False)
googleSnarfer = urlSnarfer(googleSnarfer) googleSnarfer = urlSnarfer(googleSnarfer)
def _googleUrl(self, s):
s = s.replace('+', '%2B')
s = s.replace(' ', '+')
url = r'http://google.com/search?q=' + s
return url
_calcRe = re.compile(r'<h\d class="?r"?.*?<b>(.*?)</b>', re.I)
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)
_calcFontRe = re.compile(r'<font size=-2>(.*?)</font>')
_calcTimesRe = re.compile(r'&(?:times|#215);')
def calc(self, irc, msg, args, expr):
"""<expression>
Uses Google's calculator to calculate the value of <expression>.
"""
url = self._googleUrl(expr)
html = utils.web.getUrl(url)
match = self._calcRe.search(html)
if match is not None:
s = match.group(1)
s = self._calcSupRe.sub(r'^(\1)', s)
s = self._calcFontRe.sub(r',', s)
s = self._calcTimesRe.sub(r'*', s)
irc.reply(s)
else:
irc.reply('Google\'s calculator didn\'t come up with anything.')
calc = wrap(calc, ['text'])
_phoneRe = re.compile(r'Phonebook.*?<font size=-1>(.*?)<a href')
def phonebook(self, irc, msg, args, phonenumber):
"""<phone number>
Looks <phone number> up on Google.
"""
url = self._googleUrl(phonenumber)
html = utils.web.getUrl(url)
m = self._phoneRe.search(html)
if m is not None:
s = m.group(1)
s = s.replace('<b>', '')
s = s.replace('</b>', '')
s = utils.web.htmlToText(s)
irc.reply(s)
else:
irc.reply('Google\'s phonebook didn\'t come up with anything.')
phonebook = wrap(phonebook, ['text'])
Class = Google Class = Google

View File

@ -33,21 +33,6 @@ from supybot.test import *
class GoogleTestCase(ChannelPluginTestCase): class GoogleTestCase(ChannelPluginTestCase):
plugins = ('Google',) plugins = ('Google',)
if network: if network:
def testCalcHandlesMultiplicationSymbol(self):
self.assertNotRegexp('google calc seconds in a century', r'215')
def testCalc(self):
self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t')
self.assertNotRegexp('google calc 1 usd in gbp', r'didn\'t')
def testHtmlHandled(self):
self.assertNotRegexp('google calc '
'the speed of light '
'in microns / fortnight', '<sup>')
self.assertNotRegexp('google calc '
'the speed of light '
'in microns / fortnight', '&times;')
def testSearch(self): def testSearch(self):
self.assertNotError('google foo') self.assertNotError('google foo')
self.assertRegexp('google dupa', r'dupa') self.assertRegexp('google dupa', r'dupa')
@ -58,7 +43,4 @@ class GoogleTestCase(ChannelPluginTestCase):
self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+') self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+')
self.assertNotError('fight ... !') self.assertNotError('fight ... !')
def testCalcDoesNotHaveExtraSpaces(self):
self.assertNotRegexp('google calc 1000^2', r'\s+,\s+')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: