def xkcd(jenni, input): # get latest comic for rand function and numeric input body = urllib2.urlopen("http://xkcd.com/rss.xml").readlines()[1] parsed = etree.fromstring(body) newest = etree.tostring(parsed.findall("channel/item/link")[0]) max_int = int(newest.split("/")[-3]) # if no input is given (pre - lior's edits code) if not input.group(2): # get rand comic random.seed() website = "http://xkcd.com/%d/" % random.randint(0,max_int+1) else: query = input.group(2).strip() # numeric input! get that comic number if it exists if (query.isdigit()): if (int(query) > max_int): jenni.say("Sorry, comic #" + query + " hasn't been posted yet. The last comic was #%d" % max_int) return else: website = "http://xkcd.com/" + query # non-numeric input! code lifted from search.g else: if (query.lower() == "latest" or query.lower() == "newest"): # special commands website = "https://xkcd.com/" else: # just google try: query = query.encode('utf-8') except: pass website = google_search("site:xkcd.com "+ query) chkForum = re.match(re.compile(r'.*?([0-9].*?):.*'), find_title(website)) # regex for comic specific forum threads if (chkForum): website = "http://xkcd.com/" + chkForum.groups()[0].lstrip('0') if website: # format and say result website += ' [' + find_title(website)[6:] + ']' jenni.say(website) elif website is False: jenni.say("Problem getting data from Google.") else: jenni.say("No results found for '%s'." % query)
def meetinglink(jenni, input): if not ismeetingrunning(input.sender): jenni.say('Can\'t do that, start meeting first') return if not input.group(2): jenni.say('try .action someone will do something') return if not ischair(input.nick, input.sender): jenni.say('Only meeting head or chairs can do that') return link = input.group(2) if not link.startswith("http"): link = "http://" + link try: title = find_title(link) except: title = '' logplain('LINK: %s [%s]' % (link, title), input.sender) logHTML_listitem('<a href="%s">%s</a>' % (link, title), input.sender) jenni.say('LINK: ' + link)