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

20 lines
452 B
Python
Executable file

import re
from util import hook, http, misc
from bs4 import BeautifulSoup
@hook.command("math")
@hook.command
def calc(inp):
"calc <term> -- Calculate <term> with Google Calc."
page = http.get('http://www.google.com/search', q=inp)
soup = BeautifulSoup(page, 'lxml')
response = soup.find('h2', {'class': 'r'})
if response is None:
return "Could not calculate '%s'" % inp
return http.unescape(response.contents[0])