From 6b946aad942042adab7f01ee18b3ebffa24b5d1f Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 22 Oct 2004 20:35:45 +0000 Subject: [PATCH] Added phonebook command. --- plugins/Google.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/plugins/Google.py b/plugins/Google.py index c5c891e07..34441d4c3 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -462,6 +462,12 @@ class Google(callbacks.PrivmsgCommandAndRegexp): 'Google Groups page.') googleGroups = urlSnarfer(googleGroups) + def _googleUrl(self, s): + s = s.replace('+', '%2B') + s = s.replace(' ', '+') + url = r'http://google.com/search?q=%s' % s + return url + _calcRe = re.compile(r'(.*?)', re.I) _calcSupRe = re.compile(r'(.*?)', re.I) _calcFontRe = re.compile(r'(.*?)') @@ -471,9 +477,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp): Uses Google's calculator to calculate the value of . """ - expr = expr.replace('+', '%2B') - expr = expr.replace(' ', '+') - url = r'http://google.com/search?q=%s' % expr + url = self._googleUrl(expr) html = webutils.getUrl(url) match = self._calcRe.search(html) if match is not None: @@ -486,6 +490,27 @@ class Google(callbacks.PrivmsgCommandAndRegexp): irc.reply('Google\'s calculator didn\'t come up with anything.') calc = wrap(calc, ['text']) + _phoneRe = re.compile(r'Phonebook.*?(.*?) + + Looks up on Google. + """ + url = self._googleUrl(phonenumber) + html = webutils.getUrl(url) + m = self._phoneRe.search(html) + if m is not None: + s = m.group(1) + s = s.replace('', '') + s = s.replace('', '') + s = utils.htmlToText(s) + irc.reply(s) + else: + irc.reply('Google return not phonebook results.') + phonebook = wrap(phonebook, ['text']) + + + Class = Google