Created
February 11, 2011 00:01
-
-
Save e000/821654 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def parseWolframAlphaResponse(self, response, redirected = False, results = None): | |
| results = results if results is not None else [] | |
| xmlTree = fromstring(response) | |
| recalculate = xmlTree.get('recalculate') | |
| success = xmlTree.get('success') | |
| if success == 'true': | |
| for pod in xmlTree.findall('pod'): | |
| title = pod.get('title') | |
| plaintext = pod.find('subpod/plaintext') | |
| if plaintext is not None and plaintext.text: | |
| results.append((title, plaintext.text.split('\n'))) | |
| if recalculate: | |
| if not redirected: | |
| return self.getPage(recalculate).addCallback(self.parseWolframAlphaResponse, True, results) | |
| elif results: | |
| return True, results | |
| else: | |
| return error, 'Too many redirects.' | |
| elif success == 'true': | |
| return True, results | |
| else: | |
| return False, [tip.get('text') for tip in xmlTree.findall('tips/tip')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment