From 4647e767dadab8c7e0bd78ffeaed4e641caf52e6 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 31 Aug 2013 11:18:38 -0700 Subject: [PATCH] Added handling of exponents Slightly better than my last suggestion. Why doesn't git let you edit existing pull requests?? --- plugins/gcalc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/gcalc.py b/plugins/gcalc.py index 369cd65..e559024 100755 --- a/plugins/gcalc.py +++ b/plugins/gcalc.py @@ -1,6 +1,5 @@ from util import hook, http - @hook.command("math") @hook.command def calc(inp): @@ -9,7 +8,11 @@ def calc(inp): soup = http.get_soup('http://www.google.com/search', q=inp) result = soup.find('h2', {'class': 'r'}) + exponent = result.find('sup') if not result: return "Could not calculate '%s'" % inp - return result.contents[0] + if not exponent: + return result.contents[0] + if exponent: + return result.contents[0] + "^" + exponent.contents[0]