mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
mroth's google calc.
This commit is contained in:
parent
4e10d65b56
commit
cf124a2f2b
@ -378,11 +378,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
r"http://groups.google.com/[^\s]+"
|
||||
if not self.registryValue('groupsSnarfer', msg.args[0]):
|
||||
return
|
||||
m = match.group(0)
|
||||
header = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; '
|
||||
'Windows NT 4.0)'}
|
||||
request = webutils.Request(m, headers=header)
|
||||
text = webutils.getUrl(request)
|
||||
text = webutils.getUrl(match.group(0))
|
||||
mThread = None
|
||||
mGroup = None
|
||||
if 'threadm=' in m:
|
||||
@ -411,6 +407,24 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
'Google Groups page.')
|
||||
googleGroups = privmsgs.urlSnarfer(googleGroups)
|
||||
|
||||
_calcRe = re.compile(r'<td nowrap><font size=\+1><b>(.*?)</b>', re.I)
|
||||
def calc(self, irc, msg, args):
|
||||
"""<expression>
|
||||
|
||||
Uses Google's calculator to calculate the value of <expression>.
|
||||
"""
|
||||
expr = privmsgs.getArgs(args)
|
||||
expr = expr.replace('+', '%2B')
|
||||
expr = expr.replace(' ', '+')
|
||||
url = r'http://google.com/search?q=%s' % expr
|
||||
html = webutils.getUrl(url)
|
||||
match = self._calcRe.search(html)
|
||||
if match is not None:
|
||||
irc.reply(match.group(1))
|
||||
else:
|
||||
irc.reply('Google\'s calculator didn\'t come up with anything.')
|
||||
|
||||
|
||||
|
||||
Class = Google
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user