This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/gcalc.py
Fletcher Boyd 7ab4f756fe .format
2013-09-05 09:46:49 +08:00

20 lines
484 B
Python
Executable file

from util import hook, http
@hook.command("math")
@hook.command
def calc(inp):
"""calc <term> -- Calculate <term> with Google Calc."""
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 '{}'".format(inp)
if not exponent:
return result.contents[0]
if exponent:
return "{}^{}".format(result.contents[0]*2)