def do_send_to_twitter(post_id, app_config): with async_app_context(app_config): current_app.logger.debug('auto-posting to twitter for %s', post_id) post = Post.load_by_id(post_id) in_reply_to, repost_of, like_of = util.posse_post_discovery( post, PERMALINK_RE) # cowardly refuse to auto-POSSE a reply/repost/like when the # target tweet is not found. if post.in_reply_to and not in_reply_to: current_app.logger.warn('could not find tweet to reply to for %s', post.in_reply_to) return None elif post.repost_of and not repost_of: current_app.logger.warn('could not find tweet to repost for %s', post.repost_of) preview, img_url = guess_raw_share_tweet_content(post) elif post.like_of and not like_of: current_app.logger.warn('could not find tweet to like for %s', post.like_of) return None else: preview, img_url = guess_tweet_content(post, in_reply_to) response = do_tweet(post_id, preview, img_url, in_reply_to, repost_of, like_of) return str(response)
def do_send_to_twitter(post_id, app_config): with async_app_context(app_config): current_app.logger.debug('auto-posting to twitter for %s', post_id) post = Post.load_by_id(post_id) in_reply_to, repost_of, like_of = util.posse_post_discovery( post, PERMALINK_RE) # cowardly refuse to auto-POSSE a reply/repost/like when the # target tweet is not found. if post.in_reply_to and not in_reply_to: current_app.logger.warn( 'could not find tweet to reply to for %s', post.in_reply_to) return None elif post.repost_of and not repost_of: current_app.logger.warn( 'could not find tweet to repost for %s', post.repost_of) preview, img_url = guess_raw_share_tweet_content(post) elif post.like_of and not like_of: current_app.logger.warn( 'could not find tweet to like for %s', post.like_of) return None else: preview, img_url = guess_tweet_content(post, in_reply_to) response = do_tweet(post_id, preview, img_url, in_reply_to, repost_of, like_of) return str(response)
def share_on_twitter(): if request.method == 'GET': id = request.args.get('id') if not id: abort(404) post = Post.load_by_id(id) if not post: abort(404) current_app.logger.debug('sharing on twitter. post: %s', post) in_reply_to, repost_of, like_of \ = util.posse_post_discovery(post, PERMALINK_RE) current_app.logger.debug( 'discovered in-reply-to: %s, repost-of: %s, like-of: %s', in_reply_to, repost_of, like_of) if post.repost_of and not repost_of: preview, _ = guess_raw_share_tweet_content(post) imgs = list(collect_images(post.repost_contexts[0])) else: preview, _ = guess_tweet_content(post, in_reply_to) imgs = list(collect_images(post)) current_app.logger.debug('twitter post has images: %s', imgs) return render_template('admin/share_on_twitter.jinja2', preview=preview, post=post, in_reply_to=in_reply_to, repost_of=repost_of, like_of=like_of, imgs=imgs) post_id = request.form.get('post_id') preview = request.form.get('preview') img_url = request.form.get('img') in_reply_to = request.form.get('in_reply_to') repost_of = request.form.get('repost_of') like_of = request.form.get('like_of') return do_tweet(post_id, preview, img_url, in_reply_to, repost_of, like_of)