diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index e89a90124..b7c6006f4 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -231,52 +231,6 @@ class Google(callbacks.PluginRegexp): 'filter':''}), 'text']) - @internationalizeDocstring - def cache(self, irc, msg, args, url): - """ - - Returns a link to the cached version of if it is available. - """ - data = self.search(url, msg.channel, irc.network, {'smallsearch': True}) - if data: - m = data[0] - if m['cacheUrl']: - url = m['cacheUrl'].encode('utf-8') - irc.reply(url) - return - irc.error(_('Google seems to have no cache for that site.')) - cache = wrap(cache, ['url']) - - _fight_re = re.compile(r'id="resultStats"[^>]*>(?P[^<]*)') - @internationalizeDocstring - def fight(self, irc, msg, args): - """ [ ...] - - Returns the results of each search, in order, from greatest number - of results to least. - """ - channel = msg.channel - network = irc.network - results = [] - for arg in args: - text = self.search(arg, channel, network, {'smallsearch': True}) - i = text.find('id="resultStats"') - stats = utils.web.htmlToText(self._fight_re.search(text).group('stats')) - if stats == '': - results.append((0, args)) - continue - count = ''.join(filter('0123456789'.__contains__, stats)) - results.append((int(count), arg)) - results.sort() - results.reverse() - if self.registryValue('bold', channel, network): - bold = ircutils.bold - else: - bold = repr - s = ', '.join([format('%s: %i', bold(s), i) for (i, s) in results]) - irc.reply(s) - - def _translate(self, sourceLang, targetLang, text): headers = dict(utils.web.defaultHeaders) headers['User-agent'] = ('Mozilla/5.0 (X11; U; Linux i686) ' @@ -339,59 +293,6 @@ class Google(callbacks.PluginRegexp): (self.registryValue('baseUrl', channel, network), s) return url - _calcRe1 = re.compile(r'(.*?)', re.I) - _calcRe2 = re.compile(r'
.*? - - Uses Google's calculator to calculate the value of . - """ - url = self._googleUrl(expr, msg.channel, irc.network) - h = {"User-Agent":"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"} - html = utils.web.getUrl(url, headers=h).decode('utf8') - match = self._calcRe1.search(html) - if not match: - match = self._calcRe2.search(html) - if not match: - match = self._calcRe3.search(html) - if not match: - irc.reply("I could not find an output from Google Calc for: %s" % expr) - return - else: - s = match.group(1) - else: - s = match.group(1) - else: - s = match.group(1) - # do some cleanup of text - s = re.sub(r'(.*)(.*)', r' \1/\2', s) - s = re.sub(r'(.*)', r'^\1', s) - s = utils.web.htmlToText(s) - irc.reply("%s = %s" % (expr, s)) - calc = wrap(calc, ['text']) - - _phoneRe = re.compile(r'Phonebook.*?(.*?) - - Looks up on Google. - """ - url = self._googleUrl(phonenumber, msg.channel, irc.network) - html = utils.web.getUrl(url).decode('utf8') - m = self._phoneRe.search(html) - if m is not None: - s = m.group(1) - s = s.replace('', '') - s = s.replace('', '') - 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 diff --git a/plugins/Google/test.py b/plugins/Google/test.py index aa2a302f5..57f6e27a5 100644 --- a/plugins/Google/test.py +++ b/plugins/Google/test.py @@ -34,21 +34,6 @@ from supybot.test import * class GoogleTestCase(ChannelPluginTestCase): plugins = ('Google', 'Config') 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', '') - self.assertNotRegexp('google calc ' - 'the speed of light ' - 'in microns / fortnight', '×') - def testSearch(self): self.assertNotError('google foo') self.assertRegexp('google dupa', r'dupa') @@ -76,14 +61,7 @@ class GoogleTestCase(ChannelPluginTestCase): self.assertNotError('config plugins.Google.oneToOne True') self.assertNotRegexp('google dupa', ';') - def testFight(self): - self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+') - self.assertNotError('fight ... !') - def testTranslate(self): self.assertRegexp('translate en es hello world', 'Hola mundo') - def testCalcDoesNotHaveExtraSpaces(self): - self.assertNotRegexp('google calc 1000^2', r'\s+,\s+') - # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: