def trigger_ud(self, msg): "Usage: ud <search term>. Prints first UrbanDictionary result." url = "http://www.urbandictionary.com/define.php" data = {'term':' '.join(msg.args)} soup = bs(requests.post(url,data=data).text, convertEntities=bs.HTML_ENTITIES) word = soup.find('td', 'word') if not word: self.c.privmsg(msg.channel, '%s: No entries were found.'%' '.join(msg.args)) return word = self.tag2string(word).strip() defi = self.tag2string(soup.find('div', 'definition')).split('<br')[0] self.c.privmsg(msg.channel, '%s: %s'%(word,defi,))
def trigger_w(self, msg): "Usage: w <search term>. Prints a short description of the corresponding wikipedia article." if len(msg.args) == 0: self.c.notice(msg.nick, "Please specify a search term") return params = {'action':'opensearch', 'format':'xml', 'limit':'2', 'search':' '.join(msg.args)} resp = bss(requests.post("http://en.wikipedia.org/w/api.php", data=params).text, convertEntities=bs.HTML_ENTITIES) if resp.textTag: index = 1 if 'may refer to:' in resp.descriptionTag.string else 0 info = resp.findAll('description')[index].string.strip() url = resp.findAll('url')[index].string message = u"\002Wikipedia ::\002 %s \002::\002 %s" % (info, googl.get_short(url,self.c.config)) self.c.privmsg(msg.channel, message) else: self.c.privmsg(msg.channel, '%s: No articles were found.' % ' '.join(msg.args))