From 788746c595649675ef5e8fabe1414103ccf817ec Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 3 Sep 2016 11:08:41 -0400 Subject: [PATCH] Allow other query parameters to be passed --- wolframalpha/__init__.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/wolframalpha/__init__.py b/wolframalpha/__init__.py index 94a9e7f..d64f0dd 100644 --- a/wolframalpha/__init__.py +++ b/wolframalpha/__init__.py @@ -16,18 +16,22 @@ class Client(object): def __init__(self, app_id='Q59EW4-7K8AHE858R'): self.app_id = app_id - def query(self, query, assumption=None): + def query(self, query, **data): """ Query Wolfram|Alpha using the v2.0 API - Allows for assumptions to be included. - See: http://products.wolframalpha.com/api/documentation.html#6 + + Allows for arbitrary parameters (data) to be passed in + the query. For example, to pass assumptions: + + client.query(query='pi', assumption='*C.pi-_*NamedConstant-') + + For more details on Assumptions, see + https://products.wolframalpha.com/api/documentation.html#6 """ - data = { - 'input': query, - 'appid': self.app_id - } - if assumption: - data.update({'assumption': assumption}) + data.update( + input=query, + appid=self.app_id, + ) query = urllib.parse.urlencode(data) url = 'https://api.wolframalpha.com/v2/query?' + query @@ -36,6 +40,7 @@ class Client(object): assert resp.headers.get_param('charset') == 'utf-8' return Result(resp) + class Result(object): ''' Handles processing the response for the programmer.