Esempio n. 1
0
	def trigger_ud(self, msg):
		"Usage: ud <search term>. Prints first UrbanDictionary result."

		url = "http://www.urbandictionary.com/define.php?term="+urllib.quote_plus(' '.join(msg.args))
		soup = bs(urllib2.urlopen(url), 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,))
Esempio n. 2
0
    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,))
Esempio n. 3
0
	def on_incoming(self, msg):
		if not msg.type == msg.CHANNEL: return

		urls = re.findall(r'\(?\bhttps?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]', msg.body)
		for url in urls:
			if url.startswith('(') and url.endswith(')'):
				url = url[1:-1]

			o = urlparse(url)
			conn = httplib.HTTPConnection(o.netloc)
			conn.request("HEAD", o.path)
			head = conn.getresponse()

			if 'text/html' in head.getheader('content-type'):
				message = 'Title: '+bs(urllib.urlopen(url), convertEntities=bs.HTML_ENTITIES).title.string.strip().replace('\n', '')
			else:
				message = '%s: %s (%s)' % (re.search(r'/([^/]+)$', url).groups(1)[0], head.getheader('content-type'), self.sizeof_fmt(int(head.getheader('content-length'))))
			self.c.privmsg(msg.channel, message)
Esempio n. 4
0
	def trigger_yt(self, msg):
		"Usage: yt <searchterm>. Prints title and link to first youtube result."
		if len(msg.args) == 0:
			self.c.notice(msg.nick, "Please specify a search term")
			return

		url = "http://www.youtube.com/results?search_query=%s" % (urllib.quote_plus(' '.join(msg.args)),)
		req = urllib2.Request(url, None, {'User-agent':self.useragent})
		entry = bs(urllib2.urlopen(req), convertEntities=bs.HTML_ENTITIES).find('div', 'yt-lockup-content')

		if not entry:
			self.c.privmsg(msg.channel, '%s: No entries were found.'%' '.join(msg.args))
			return

		message = "\002You\0030,4Tube\003 ::\002 %s \002::\002 %s \002::\002 %s" % (
			entry.find('a', 'yt-uix-contextlink').string,
			self.tag2string(entry.find('p', 'description')),
			"www.youtube.com"+entry.find('a', 'yt-uix-contextlink')['href'],)
		self.c.privmsg(msg.channel, message)
Esempio n. 5
0
	def trigger_g(self, msg):
		"Usage: g <search term>. Prints title & short description of first google result."
		if len(msg.args) == 0:
			self.c.notice(msg.nick, "Please specify a search term")
			return

		url = "https://www.google.com.au/search?q=%s" % (urllib.quote_plus(' '.join(msg.args)),)
		req = urllib2.Request(url, None, {'User-agent':self.useragent})
		entry = bs(urllib2.urlopen(req), convertEntities=bs.HTML_ENTITIES).find('div', 'vsc')

		if not entry:
			self.c.privmsg(msg.channel, '%s: No entries were found.'%' '.join(msg.args))
			return

		url = googl.get_short(entry.find('a','l')['href'], self.c.config)
		message = "\002\0032G\0034o\0038o\0032g\0033l\0034e\003 ::\002 %s \002::\002 %s \002::\002 %s" % (
			self.tag2string(entry.find('a','l')),
			self.tag2string(entry.find('span','st')),
			url,)
		self.c.privmsg(msg.channel, message)
Esempio n. 6
0
 def fix_text(self, text):
     soup = bs(text, convertEntities=bs.HTML_ENTITIES)
     return self.tag2string(soup, keep_bold=True)