Added handling of exponents
Slightly better than my last suggestion. Why doesn't git let you edit existing pull requests??
This commit is contained in:
parent
3a6f18f67b
commit
4647e767da
1 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,5 @@
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
@hook.command("math")
|
@hook.command("math")
|
||||||
@hook.command
|
@hook.command
|
||||||
def calc(inp):
|
def calc(inp):
|
||||||
|
@ -9,7 +8,11 @@ def calc(inp):
|
||||||
soup = http.get_soup('http://www.google.com/search', q=inp)
|
soup = http.get_soup('http://www.google.com/search', q=inp)
|
||||||
|
|
||||||
result = soup.find('h2', {'class': 'r'})
|
result = soup.find('h2', {'class': 'r'})
|
||||||
|
exponent = result.find('sup')
|
||||||
if not result:
|
if not result:
|
||||||
return "Could not calculate '%s'" % inp
|
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]
|
||||||
|
|
Reference in a new issue