diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2012-08-25 22:54:16 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2012-08-25 22:54:16 +0200 |
commit | 59d69707083a9050fcaf77402f86eb1665277f10 (patch) | |
tree | b9c1f9672502f36d74342111a8d8a0a6b41f9b5f | |
parent | 1d6d92d2dd1bf9d87d7065b46e8a60086cd05c02 (diff) |
wolframalpha: Show all pods with plaintext subpods.
-rw-r--r-- | modules/wolframalpha.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 0750578..910698f 100644 --- a/modules/wolframalpha.py +++ b/modules/wolframalpha.py @@ -4,9 +4,11 @@ info = { 'description': 'WolframAlpha', } -import urllib, urllib2 +import urllib, urllib2, re from lxml.etree import ElementTree +whitespace_re = re.compile(r'\s+') + class Module(object): config_section = 'module/wolframalpha' @@ -33,11 +35,15 @@ class Module(object): self.irc.msg(target, 'No result.') return - result = None + results = [] for pod in xml.findall('pod'): - if pod.attrib['id'] == 'Result': - result = pod.find('subpod/plaintext').text - if result: - self.irc.msg(target, 'Result: %s' % result) + #if pod.attrib['id'] == 'Result': + result = pod.find('subpod/plaintext') + if result is not None: + text = result.text + text = whitespace_re.sub(' ', text) + results.append('\002%s\002: %s' % (pod.attrib['title'], text)) + if len(results): + self.irc.msg(target, ' '.join(results)) else: self.irc.msg(target, 'Something failed.') |