From 59d69707083a9050fcaf77402f86eb1665277f10 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 25 Aug 2012 22:54:16 +0200 Subject: wolframalpha: Show all pods with plaintext subpods. --- modules/wolframalpha.py | 18 ++++++++++++------ 1 file 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.') -- cgit v1.2.3