From 4b7cbb118cbabb0d133cdf58fd46d384a0002e61 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 4 Sep 2012 09:28:24 +1200 Subject: [PATCH] Updated gcalc.py to use included copy of BeautifulSoup. --- plugins/gcalc.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/plugins/gcalc.py b/plugins/gcalc.py index 52c6644..f8035cd 100755 --- a/plugins/gcalc.py +++ b/plugins/gcalc.py @@ -1,7 +1,7 @@ import re from util import hook, http, misc -from BeautifulSoup import BeautifulSoup +from bs4 import BeautifulSoup @hook.command("math") @@ -9,24 +9,11 @@ from BeautifulSoup import BeautifulSoup def calc(inp): "calc -- Calculate with Google Calc." - white_re = re.compile(r'\s+') - page = http.get('http://www.google.com/search', q=inp) - - soup = BeautifulSoup(page) + soup = BeautifulSoup(page, 'lxml') response = soup.find('h2', {'class': 'r'}) - if response is None: - return "Could not calculate " + inp + return "Could not calculate '%s'" % inp - output = response.renderContents() - - output = ' '.join(output.splitlines()) - output = output.replace("\xa0", ",") - output = white_re.sub(' ', output.strip()) - - output = output.decode('utf-8', 'ignore') - output = misc.strip_html(output) - - return output + return http.unescape(response.contents[0])