import re from util import hook, http @hook.command def calc(inp): '''.calc -- returns Google Calculator result''' if not inp: return calc.__doc__ page = http.get('http://www.google.com/search', q=inp) # ugh, scraping HTML with regexes m = re.search(r'

(.*?)', page) if m is None: return "could not calculate " + inp result = m.group(1).replace(" ", ",") result = result.replace(" × 10", "E").replace("", "") result = result.replace("\xa0", ",") return result