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':urllib.quote_plus(' '.join(msg.args))} resp = bss(urllib.urlopen("http://en.wikipedia.org/w/api.php?%s" % urllib.urlencode(params)), convertEntities=bs.HTML_ENTITIES) if resp.textTag: index = 1 if 'may refer to:' in resp.descriptionTag.string else 0 self.c.privmsg(msg.channel, resp.findAll('description')[index].string) else: self.c.privmsg(msg.channel, '%s: No articles were found.'%' '.join(msg.args))
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))