__module_name__ = "pyChuckBot"__module_version__ = "1.0"__module_description__ = "Parses A website for 5 random chuck norris facts"import xchat, pycurl, StringIO, re, time, osoldtime = 0def reply(word, word_eol, userdata): """Takes everything that is said in the chat and checks for the word google, then curls for the search terms and prints the top 5 URLS""" mt = time.time() ot = globals()['oldtime'] if mt >= ot + 5: p = re.compile('!chuck', re.IGNORECASE) # Search for google within the text m = p.search(word[1]) # If triggered then parse the website if m: c = pycurl.Curl() c.setopt(pycurl.URL, "http://66.111.201.60/chuck/rss.php" ) b = StringIO.StringIO() c.setopt(pycurl.WRITEFUNCTION, b.write) c.setopt(pycurl.FOLLOWLOCATION, 1) c.setopt(pycurl.MAXREDIRS, 5) c.perform() # Find the links within the html h = re.compile("<title>(.*?\\.)<\\/title>") top5 = h.findall(b.getvalue()) for i in range(1): try: xchat.command("say " + top5[i]) except IndexError: if i == 0: xchat.command("say I cant find a result for that, sorry") else: xchat.command("say wait up a sec") globals()['oldtime'] = mtxchat.hook_print("Channel Message", reply)