def cmd_gag(self, msg, args): """!gag - return a random image from 9gag.""" try: data = htmlparse("http://9gag.com/random", ".badge-item-animated-img") title = data.attr("alt") img = data.attr("src") except: data = htmlparse("http://9gag.com/random", ".badge-item-img") title = data.attr("alt") img = data.attr("src") # We need to duplicate data access here cuz of the object is not really parsed until # attr is invoked. self.send(msg['from'], img, msg['type']) return str(title)
def cmd_devopsme(self, msg, args): """!devopsme - return a random image from devopsreactions.""" data = htmlparse("http://devopsreactions.tumblr.com/random", ".item_content") title = data.find(".post_title").find("a").text() img = data.find("p").find("img").attr("src") self.send(msg['from'], img, msg['type']) return str(title)