Added some objects for working with wolframalpha

This commit is contained in:
Jason R. Coombs 2012-10-03 18:44:06 -04:00
parent 772ce9b34d
commit c4ac852a68
2 changed files with 29 additions and 1 deletions

View File

@ -6,6 +6,33 @@ class Result(object):
def __init__(self, stream): def __init__(self, stream):
self.tree = etree.parse(stream) self.tree = etree.parse(stream)
@property
def pods(self):
return map(Pod, self.tree.findall('pod'))
class Pod(object):
def __init__(self, node):
self.node = node
self.__dict__.update(node.attrib)
def __iter__(self):
return (Content(node) for node in self.nodes.findall('subpod'))
@property
def main(self):
"The main content of this pod"
return next(iter(self))
@property
def text(self):
return self.main.text
class Content(object):
def __init__(self, node):
self.node = node
self.__dict__.update(node.attrib)
self.text = node.find('plaintext').text
class Client(object): class Client(object):
""" """
Wolfram|Alpha v2.0 client Wolfram|Alpha v2.0 client

View File

@ -5,4 +5,5 @@ app_id = 'Q59EW4-7K8AHE858R'
def test_basic(): def test_basic():
client = wolframalpha.Client(app_id) client = wolframalpha.Client(app_id)
client.query('30 deg C in deg F') res = client.query('30 deg C in deg F')
import pytest; pytest.set_trace()