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

16 lines
346 B
Python
Raw Normal View History

2012-09-04 21:52:03 +02:00
from util import hook, http
2011-11-20 10:23:31 +01:00
2012-03-12 19:13:32 +01:00
2011-11-20 10:23:31 +01:00
@hook.command("math")
2012-03-12 19:13:32 +01:00
@hook.command
2011-11-20 10:23:31 +01:00
def calc(inp):
2012-05-16 05:07:27 +02:00
"calc <term> -- Calculate <term> with Google Calc."
2011-11-20 10:23:31 +01:00
2012-09-05 01:41:32 +02:00
soup = http.get_soup('http://www.google.com/search', q=inp)
2011-11-20 10:23:31 +01:00
2012-12-09 13:59:33 +01:00
result = soup.find('h2', {'class': 'r'})
if not result:
return "Could not calculate '%s'" % inp
2011-11-20 10:23:31 +01:00
2012-12-09 13:59:33 +01:00
return result.contents[0]