Added some objects for working with wolframalpha
This commit is contained in:
parent
772ce9b34d
commit
c4ac852a68
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user