<commit_before>
import urllib2
from urllib import quote

from commands.miscLib.xml_to_dict import xml_to_dict

appid = ""

ID = "wolfram"
permission = 3

class WolframAlpha():
    def __init__(self, appid):
        self.appid = appid
        self.url = "http://api.wolframalpha.com/v1/query.jsp"+"?appid="+quote(appid)
        
    def submit(self, inputstring):
        inputstring = quote(inputstring)
        urlstring = self.url+"&input="+inputstring
        
        data = urllib2.urlopen(urlstring, timeout = 8)
        result = data.read()
        
        return result
        
def __initialize__(self, Startup):
    self.WolframAlpha = WolframAlpha(appid)

def execute(self, name, params, channel, userdata, rank):
    request = " ".join(params)
    request = request.strip()
    
    if len(request) > 1:
        try:
            result = self.WolframAlpha.submit(request)
            xmldict = xml_to_dict(result)
            pod = xmldict["queryresult"]["pod"]
            
            for item in pod:
                description = item["@title"]
                result = item["subpod"]["plaintext"]
                
                if result != None:
                    result = result.strip("| ")
                    result = result.replace(" | ", ": ")
                    result = " | ".join(result.split("\n"))
                   
                    
                    self.sendMessage(channel, "{0}: {1}".format(description, result))
            
        except Exception as error:
            self.sendMessage(channel, "Error appeared: {0}".format(str(error)))<commit_msg>Fixed bug that would raise an exception because in some cases the subpod section is a list instead of a dictionary. Now iterates over the list and retrieves the result from each entry.<commit_after>
import urllib2
import traceback

from urllib import quote

from commands.miscLib.xml_to_dict import xml_to_dict

appid = ""

ID = "wolfram"
permission = 3

class WolframAlpha():
    def __init__(self, appid):
        self.appid = appid
        self.url = "http://api.wolframalpha.com/v1/query.jsp"+"?appid="+quote(appid)
        
    def submit(self, inputstring):
        inputstring = quote(inputstring)
        urlstring = self.url+"&input="+inputstring
        
        data = urllib2.urlopen(urlstring, timeout = 8)
        result = data.read()
        
        return result
        
def __initialize__(self, Startup):
    self.WolframAlpha = WolframAlpha(appid)

def execute(self, name, params, channel, userdata, rank):
    request = " ".join(params)
    request = request.strip()
    
    if len(request) > 1:
        try:
            result = self.WolframAlpha.submit(request)
            xmldict = xml_to_dict(result)
            pod = xmldict["queryresult"]["pod"]
            
            for item in pod:
                description = item["@title"]
                #print item
                #print item["subpod"]
                if not isinstance(item["subpod"], list):
                    result = item["subpod"]["plaintext"]
                    
                    if result != None:
                        result = result.strip("| ")
                        result = result.replace(" | ", ": ")
                        result = " | ".join(result.split("\n"))
                       
                        
                        self.sendMessage(channel, "{0}: {1}".format(description, result))
                else:
                    entries = []
                    for subpod in item["subpod"]:
                        result = subpod["plaintext"]
                        
                        if result != None:
                            result = result.strip("| ")
                            result = result.replace(" | ", ": ")
                            result = " | ".join(result.split("\n"))
                           
                            entries.append(result)
                    
                    self.sendMessage(channel, "{0}: {1}".format(description, " | ".join(entries)))
                    
            
        except Exception as error:
            self.sendMessage(channel, "Error appeared: {0}".format(str(error)))
            traceback.print_exc()
{'fraction_non_alphanumeric': 0.11369570377403275, 'fraction_numerical': 0.004747211013529551, 'mean_word_length': 1.5416164053075996, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4973498', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1118, 'n_words': 254}