From c1d9023bd32987d8c097edc1b7ad91b270eff852 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 3 Oct 2012 18:13:39 -0400 Subject: [PATCH] Early implementation --- setup.py | 1 + wolframalpha/__init__.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/setup.py b/setup.py index 6c545c9..f13817d 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import setuptools setup_params = dict( name='wolframalpha', + description="Wolfram|Alpha 2.0 API client", use_hg_version=True, author="Jason R. Coombs", author_email="jaraco@jaraco.com", diff --git a/wolframalpha/__init__.py b/wolframalpha/__init__.py index e69de29..7e271c4 100644 --- a/wolframalpha/__init__.py +++ b/wolframalpha/__init__.py @@ -0,0 +1,27 @@ +import urllib +import urllib2 +from xml.etree import ElementTree as etree + +class Result(object): + def __init__(self, stream): + self.tree = etree.parse(stream) + +class Client(object): + """ + Wolfram|Alpha v2.0 client + """ + def __init__(self, app_id): + self.app_id = app_id + + def query(self, query): + """ + Query Wolfram|Alpha with query using the v2.0 API + """ + query = urllib.urlencode(dict( + input=query, + appid=self.app_id, + )) + url = 'http://api.wolframalpha.com/v2/query?' + query + resp = urllib2.urlopen(url) + assert resp.headers['Content-Type'] == 'application/xml' + return Result(resp)