def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return self.user = self.get_author_user() access_token = json.loads(self.user.twitter) #thumb = self.get_argument('thumb', '') # XXX TODO multipart doesn't work for some reason right now... arrrgh thumb = None text_length = 79 if thumb else 99 title = self.get_argument('title', '') view = self.get_argument('view', '') status = (content_logic.ellipsize( content_remote.strip_html(title), 18, including_dots=True) + (': ' if title and view else '') + content_logic.ellipsize( content_remote.strip_html(view.replace('<br>', ' ')), text_length, including_dots=True) + (' ' if title or view else '') + self.get_argument('url')) if thumb: thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) image = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if (os.path.exists(original_img) and os.path.getsize(original_img) < 3145728): image = original_img f = open(image, 'r') image_data = f.read() f.close() self.twitter_request(self.UPDATE_WITH_MEDIA_URL, self.status_update_result, access_token=access_token, post_args={ "status": status, "media[]": image_data }) else: self.twitter_request("/statuses/update", self.status_update_result, access_token=access_token, post_args={"status": status})
def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return self.user = self.get_author_user() access_token = json.loads(self.user.twitter) #thumb = self.get_argument('thumb', '') # XXX TODO multipart doesn't work for some reason right now... arrrgh thumb = None text_length = 79 if thumb else 99 title = self.get_argument('title', '') view = self.get_argument('view', '') status = (content_logic.ellipsize(content_remote.strip_html( title), 18, including_dots=True) + (': ' if title and view else '') + content_logic.ellipsize(content_remote.strip_html( view.replace('<br>', ' ')), text_length, including_dots=True) + (' ' if title or view else '') + self.get_argument('url')) if thumb: thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) image = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if (os.path.exists(original_img) and os.path.getsize(original_img) < 3145728): image = original_img f = open(image, 'r') image_data = f.read() f.close() self.twitter_request( self.UPDATE_WITH_MEDIA_URL, self.status_update_result, access_token=access_token, post_args={"status": status, "media[]": image_data }) else: self.twitter_request( "/statuses/update", self.status_update_result, access_token=access_token, post_args={"status": status})
def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return self.user = self.get_author_user() access_token = self.user.facebook title = self.get_argument('title', '') view = self.get_argument('view', '') status = (content_remote.strip_html(title) + ('\n' if title and view else '') + content_remote.strip_html(view.replace('<br>', ' ')) + ('\n' if title or view else '') + self.get_argument('url')) post_args = {"message": status} thumb = self.get_argument('thumb', '') picture = None if thumb: if not thumb.startswith('http://'): thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) picture = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if os.path.exists(original_img): picture = original_img picture = picture[len(self.application.settings["static_path"]) + 1:] picture = self.static_url(picture, include_host=True) else: picture = thumb if picture: post_args['picture'] = picture video = re.compile(r'<iframe[^>]*(youtube|vimeo)[^>]*>.*?</iframe>', re.M | re.S).search(view) if video: video = video.group(0) is_youtube = re.compile(r'<iframe[^>]*(youtube)[^>]*>', re.M).search( view) if is_youtube: video_id = re.compile(r'<iframe[^>]*youtube.com/embed/([^\?]*)[^>]*>', re.M).search(view).group(1) source = 'http://www.youtube.com/e/' + video_id + '?autoplay=1' else: video_id = re.compile(r'<iframe[^>]*vimeo.com/video/([^\?"]*)[^>]*>', re.M).search(view).group(1) source = ('https://secure.vimeo.com/moogaloop.swf?clip_id=' + video_id + '&autoplay=1') post_args['source'] = source self.facebook_request( "/me/feed", self.status_update_result, access_token=access_token, post_args=post_args,)
def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return access_token, tumblr_info = self.get_tumblr_info() title = content_remote.strip_html(self.get_argument('title', '')) body = url_factory.add_base_uris(self, self.get_argument('view', '')) \ + '\n' \ + self.get_argument('url') post_args = {"type": "text", "title": title, "body": body} # TODO, refactor out w FB logic thumb = self.get_argument('thumb', '') picture = None normal_picture = None if thumb: if not thumb.startswith('http://'): thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) picture = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if os.path.exists(original_img): picture = original_img normal_path = os.path.join(parent_dir, basename) if os.path.exists(normal_path): normal_picture = normal_path normal_picture = normal_picture[ len(self.application.settings["static_path"]) + 1:] normal_picture = self.static_url(normal_picture, include_host=True, include_sig=False) picture = picture[len(self.application.settings["static_path"] ) + 1:] picture = self.static_url(picture, include_host=True, include_sig=False) else: picture = thumb video = re.compile(r'<iframe[^>]*(youtube|vimeo)[^>]*>.*?</iframe>', re.M | re.S).search(body) if picture and normal_picture and not video: post_args["source"] = picture post_args["link"] = self.get_argument('url') post_args["caption"] = re.compile( r'(<figure>.*?<img.*?src="' + normal_picture + r'".*?>.*?</figure>)', re.M | re.U | re.S).sub('', body) post_args["type"] = "photo" if video: video = video.group(0) post_args["embed"] = video post_args["caption"] = body.replace(video, '') post_args["type"] = "video" section = self.get_argument('section', '') album = self.get_argument('album', '') tags = re.compile(r'#(\w+)(?![^<&]*(?:[>;]))', re.M | re.U).findall(body) post_args["tags"] = "" if tags: post_args["tags"] += ','.join(tags) if section: post_args["tags"] += "," + section if album: post_args["tags"] += "," + album self.tumblr_request( "http://api.tumblr.com/v2/blog/" + tumblr_info['primary_blog'] + "/post", self.status_update_result, access_token=access_token, post_args=post_args, )
def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return self.user = self.get_author_user() access_token = self.user.facebook title = self.get_argument('title', '') view = self.get_argument('view', '') status = (content_remote.strip_html(title) + ('\n' if title and view else '') + content_remote.strip_html(view.replace('<br>', ' ')) + ('\n' if title or view else '') + self.get_argument('url')) post_args = {"message": status} thumb = self.get_argument('thumb', '') picture = None if thumb: if not thumb.startswith('http://'): thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) picture = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if os.path.exists(original_img): picture = original_img picture = picture[len(self.application.settings["static_path"] ) + 1:] picture = self.static_url(picture, include_host=True) else: picture = thumb if picture: post_args['picture'] = picture video = re.compile(r'<iframe[^>]*(youtube|vimeo)[^>]*>.*?</iframe>', re.M | re.S).search(view) if video: video = video.group(0) is_youtube = re.compile(r'<iframe[^>]*(youtube)[^>]*>', re.M).search(view) if is_youtube: video_id = re.compile( r'<iframe[^>]*youtube.com/embed/([^\?]*)[^>]*>', re.M).search(view).group(1) source = 'http://www.youtube.com/e/' + video_id + '?autoplay=1' else: video_id = re.compile( r'<iframe[^>]*vimeo.com/video/([^\?"]*)[^>]*>', re.M).search(view).group(1) source = ('https://secure.vimeo.com/moogaloop.swf?clip_id=' + video_id + '&autoplay=1') post_args['source'] = source self.facebook_request( "/me/feed", self.status_update_result, access_token=access_token, post_args=post_args, )
def post(self): if not self.authenticate(author=True): return op = self.get_argument('op', None) if op == 'favorite': self.favorite() return access_token, tumblr_info = self.get_tumblr_info() title = content_remote.strip_html(self.get_argument('title', '')) body = url_factory.add_base_uris(self, self.get_argument('view', '')) \ + '\n' \ + self.get_argument('url') post_args = {"type": "text", "title": title, "body": body} # TODO, refactor out w FB logic thumb = self.get_argument('thumb', '') picture = None normal_picture = None if thumb: if not thumb.startswith('http://'): thumb = url_factory.clean_filename(thumb) thumb = thumb[len(url_factory.resource_url(self)) + 1:] thumb = url_factory.resource_directory(self, thumb) picture = thumb basename = os.path.basename(thumb) dirname = os.path.dirname(thumb) if os.path.basename(dirname) == 'thumbs': parent_dir = os.path.dirname(dirname) original_dir = os.path.join(parent_dir, 'original') original_img = os.path.join(original_dir, basename) if os.path.exists(original_img): picture = original_img normal_path = os.path.join(parent_dir, basename) if os.path.exists(normal_path): normal_picture = normal_path normal_picture = normal_picture[len( self.application.settings["static_path"]) + 1:] normal_picture = self.static_url(normal_picture, include_host=True, include_sig=False) picture = picture[len(self.application.settings["static_path"]) + 1:] picture = self.static_url(picture, include_host=True, include_sig=False) else: picture = thumb video = re.compile(r'<iframe[^>]*(youtube|vimeo)[^>]*>.*?</iframe>', re.M | re.S).search(body) if picture and normal_picture and not video: post_args["source"] = picture post_args["link"] = self.get_argument('url') post_args["caption"] = re.compile(r'(<figure>.*?<img.*?src="' + normal_picture + r'".*?>.*?</figure>)', re.M | re.U | re.S).sub( '', body) post_args["type"] = "photo" if video: video = video.group(0) post_args["embed"] = video post_args["caption"] = body.replace(video, '') post_args["type"] = "video" section = self.get_argument('section', '') album = self.get_argument('album', '') tags = re.compile(r'#(\w+)(?![^<&]*(?:[>;]))', re.M | re.U).findall(body) post_args["tags"] = "" if tags: post_args["tags"] += ','.join(tags) if section: post_args["tags"] += "," + section if album: post_args["tags"] += "," + album self.tumblr_request( "http://api.tumblr.com/v2/blog/" + tumblr_info['primary_blog'] + "/post", self.status_update_result, access_token=access_token, post_args=post_args,)