def linker(self, urls): for url in urls: # Special behaviour for Twitter URLs match_twitter_urls = re.compile('http[s]?://(www.)?twitter.com/.+/status/([0-9]+)') twitter_urls = match_twitter_urls.findall(url) if len(twitter_urls): self.tweet(twitter_urls) return if url.find('gist.github') != -1: return if randint(1, 5) == 1: try: self.commands.get('tweet', self.default)(url) except: pass fubs = 0 title = "Couldn't get title" site = Browse(url) if site.error: self.chat('Total fail: %s' % site.error) continue roasted = shorten(url) if not roasted: roasted = "Couldn't roast" fubs += 1 try: ext = site.headers()['content-type'].split('/')[1] except: ext = False images = [ 'gif', 'png', 'jpg', 'jpeg', ] if ext in images: title = 'Image' # Switch this to a Browse method if STORE_IMGS: fname = url.split('/').pop() path = IMGS + fname self.butler.do(savefromweb, (url, path, self.lastsender), 'Thumb @ %s') elif ext == 'pdf': title = 'PDF Document' else: title = site.title() # If you have a delicious account set up. Yes, delicious # still exists. Could be updated to a cooler link # collecting service. if STORE_URLS: postdelicious(url, title, self.lastsender) if fubs == 2: self.chat("Total fail") else: self.chat("%s @ %s" % (unescape(title), roasted))
def linker(self, urls): for url in urls: # Special behaviour for Twitter URLs match_twitter_urls = re.compile( 'http[s]?://(www.)?twitter.com/.+/status/([0-9]+)') twitter_urls = match_twitter_urls.findall(url) if len(twitter_urls): self.tweet(twitter_urls) return if url.find('gist.github') != -1: return if randint(1, 5) == 1: try: self.commands.get('tweet', self.default)(url) except: pass fubs = 0 title = "Couldn't get title" site = Browse(url) if site.error: self.chat('Total fail: %s' % site.error) continue roasted = shorten(url) if not roasted: roasted = "Couldn't roast" fubs += 1 try: ext = site.headers()['content-type'].split('/')[1] except: ext = False images = [ 'gif', 'png', 'jpg', 'jpeg', ] if ext in images: title = 'Image' # Switch this to a Browse method if STORE_IMGS: fname = url.split('/').pop() path = IMGS + fname self.butler.do(savefromweb, (url, path, self.lastsender), 'Thumb @ %s') elif ext == 'pdf': title = 'PDF Document' else: title = site.title() # If you have a delicious account set up. Yes, delicious # still exists. Could be updated to a cooler link # collecting service. if STORE_URLS: postdelicious(url, title, self.lastsender) if fubs == 2: self.chat("Total fail") else: self.chat("%s @ %s" % (unescape(title), roasted))