Ejemplo n.º 1
0
def tweet_new_post_task(post_id):

    try:
        twitter = Twitter()
    except:
        return

    post = Post.objects.get(id=post_id)

    is_mod = post.author.is_administrator_or_moderator()
    if is_mod or post.author.reputation > askbot_settings.MIN_REP_TO_TWEET_ON_OTHERS_ACCOUNTS:
        tweeters = User.objects.filter(social_sharing_mode=const.SHARE_EVERYTHING)
        tweeters = tweeters.exclude(id=post.author.id)
        access_tokens = tweeters.values_list('twitter_access_token', flat=True)
    else:
        access_tokens = list()

    tweet_text = post.as_tweet()

    for raw_token in access_tokens:
        token = simplejson.loads(raw_token)
        twitter.tweet(tweet_text, access_token=token)

    if post.author.social_sharing_mode != const.SHARE_NOTHING:
        token = simplejson.loads(post.author.twitter_access_token)
        twitter.tweet(tweet_text, access_token=token)
Ejemplo n.º 2
0
def tweet_new_post_task(post_id):
    try:
        twitter = Twitter()
    except:
        return

    post = Post.objects.get(id=post_id)

    is_mod = post.author.is_administrator_or_moderator()
    if is_mod or post.author.reputation > askbot_settings.MIN_REP_TO_TWEET_ON_OTHERS_ACCOUNTS:
        tweeters = User.objects.filter(
            askbot_profile__social_sharing_mode=const.SHARE_EVERYTHING)
        tweeters = tweeters.exclude(id=post.author.id)
        access_tokens = tweeters.values_list('twitter_access_token', flat=True)
    else:
        access_tokens = list()

    tweet_text = post.as_tweet()

    for raw_token in access_tokens:
        token = simplejson.loads(raw_token)
        twitter.tweet(tweet_text, access_token=token)

    if post.author.social_sharing_mode != const.SHARE_NOTHING:
        token = simplejson.loads(post.author.twitter_access_token)
        twitter.tweet(tweet_text, access_token=token)