diff options
-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.') |