2010-04-23 03:47:41 +00:00
|
|
|
from util import hook, http
|
2010-02-22 17:25:01 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-03-01 01:39:29 +00:00
|
|
|
@hook.command
|
|
|
|
def calc(inp):
|
|
|
|
'''.calc <term> -- returns Google Calculator result'''
|
2010-02-22 17:25:01 +00:00
|
|
|
|
2011-11-07 20:16:56 +00:00
|
|
|
h = http.get_html('http://www.google.com/search', q=inp)
|
2010-02-22 17:25:01 +00:00
|
|
|
|
2011-11-07 20:16:56 +00:00
|
|
|
m = h.xpath('//h2[@class="r"]/text()')
|
2010-02-22 17:25:01 +00:00
|
|
|
|
2011-11-07 20:16:56 +00:00
|
|
|
if not m:
|
2010-03-01 01:39:29 +00:00
|
|
|
return "could not calculate " + inp
|
2010-02-22 17:25:01 +00:00
|
|
|
|
2011-11-07 20:16:56 +00:00
|
|
|
res = ' '.join(m[0].split())
|
|
|
|
|
|
|
|
return res
|