Updated gcalc.py to use included copy of BeautifulSoup.

This commit is contained in:
Luke Rogers 2012-09-04 09:28:24 +12:00
parent 6b4042972b
commit 4b7cbb118c

View file

@ -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 <term> -- Calculate <term> 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])