Commits

Jason R. Coombs committed 05fefe1

Added some objects for working with wolframalpha

Comments (0)

Files changed (2)

wolframalpha/__init__.py

     def __init__(self, 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):
     """
     Wolfram|Alpha v2.0 client

wolframalpha/test_client.py

 
 def test_basic():
 	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()