@@ -0,0 +1,60 @@
1+# Wolfram Alpha (Maths)
3+# @website http://www.wolframalpha.com
4+# @provide-api yes (http://api.wolframalpha.com/v2/)
11+from urllib import urlencode
12+from lxml import etree
15+base_url = 'http://api.wolframalpha.com/v2/query'
16+search_url = base_url + '?appid={api_key}&{query}&format=plaintext'
21+def request(query, params):
22+ params['url'] = search_url.format(query=urlencode({'input': query}),
28+# replace private user area characters to make text legible
29+def replace_pua_chars(text):
30+ pua_chars = {u'\uf74c': 'd',
31+ u'\uf74d': u'\u212f',
35+ for k, v in pua_chars.iteritems():
36+ text = text.replace(k, v)
41+# get response from search-request
45+ search_results = etree.XML(resp.content)
47+ # return empty array if there are no results
48+ if search_results.xpath('/queryresult[attribute::success="false"]'):
52+ result = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')[0].text
53+ result = replace_pua_chars(result)
56+ # TODO: shouldn't it bind the source too?
57+ results.append({'answer': result})