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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.