Google: add some extra matching capability to google calc

now should be able to display any 'special' result from google.
This commit is contained in:
Daniel Folkinshteyn 2010-12-01 16:52:01 -05:00 committed by Valentin Lorentz
parent b0bd346775
commit 7c7b093b33
3 changed files with 10 additions and 2 deletions

View File

@ -302,7 +302,8 @@ class Google(callbacks.PluginRegexp):
url = r'http://google.com/search?q=' + s
return url
_calcRe = re.compile(r'<h\d class="?r"?.*?<b>(.*?)</b>', re.I)
_calcRe1 = re.compile(r'<table.*class="?obcontainer"?[^>]*>(.*?)</table>', re.I)
_calcRe2 = 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);')
@ -314,12 +315,15 @@ class Google(callbacks.PluginRegexp):
"""
url = self._googleUrl(expr)
html = utils.web.getUrl(url)
match = self._calcRe.search(html)
match = self._calcRe1.search(html)
if match is None:
match = self._calcRe2.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)
s = utils.web.htmlToText(s)
irc.reply(s)
else:
irc.reply(_('Google\'s calculator didn\'t come up with anything.'))

View File

@ -39,6 +39,7 @@ class GoogleTestCase(ChannelPluginTestCase):
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')
self.assertRegexp('google calc current time in usa', r'Time in.*USA')
def testHtmlHandled(self):
self.assertNotRegexp('google calc '

3
src/version.py Normal file
View File

@ -0,0 +1,3 @@
"""stick the various versioning attributes in here, so we only have to change
them once."""
version = '0.83.4.1+gribble (2010-10-10T17:52:04-0400)'