Early implementation
This commit is contained in:
parent
5c3f935a84
commit
c1d9023bd3
1
setup.py
1
setup.py
|
@ -4,6 +4,7 @@ import setuptools
|
||||||
|
|
||||||
setup_params = dict(
|
setup_params = dict(
|
||||||
name='wolframalpha',
|
name='wolframalpha',
|
||||||
|
description="Wolfram|Alpha 2.0 API client",
|
||||||
use_hg_version=True,
|
use_hg_version=True,
|
||||||
author="Jason R. Coombs",
|
author="Jason R. Coombs",
|
||||||
author_email="jaraco@jaraco.com",
|
author_email="jaraco@jaraco.com",
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue
Block a user