def distribute_recommendations():
    """ Distribute new recommendations as status updates on twitter.
    """
    t = Twitter(auth=OAuth(Config.access_token, Config.access_token_secret, Config.api_key, Config.api_secret))
    recs = RecommendationDao.get_new_recommendations()

    for rec in recs:
        t.statuses.update(status=rec.text, in_reply_to_status_id=rec.userTweet.twitterId)
        RecommendationDao.update_status(rec, Enums.RecommendationStatus.done)
def get_recommendation():
    new_tweets = UserTweetDao.get_new_user_tweets()

    for tweet in new_tweets:
        UserTweetDao.update_status(tweet, Enums.UserTweetStatus.requested)
        rec_input_list = get_rec_input_from_tweet(tweet)

        rec = None

        if len(rec_input_list) > 0:
            rec = recommend(rec_input_list)

        if rec is not None:
            text = get_rec_text_for_tweet(tweet, rec)
            RecommendationDao.create_recommendation(tweet.id, rec.fullRec, text)
            UserTweetDao.update_status(tweet, Enums.UserTweetStatus.done)
        else:
            UserTweetDao.update_status(tweet, Enums.UserTweetStatus.no_recommendation)
示例#3
0
def get_recommendation():
    new_tweets = UserTweetDao.get_new_user_tweets()

    for tweet in new_tweets:
        UserTweetDao.update_status(tweet, Enums.UserTweetStatus.requested)
        rec_input_list = get_rec_input_from_tweet(tweet)

        rec = None

        if len(rec_input_list) > 0:
            rec = recommend(rec_input_list)

        if rec is not None:
            text = get_rec_text_for_tweet(tweet, rec)
            RecommendationDao.create_recommendation(tweet.id, rec.fullRec,
                                                    text)
            UserTweetDao.update_status(tweet, Enums.UserTweetStatus.done)
        else:
            UserTweetDao.update_status(tweet,
                                       Enums.UserTweetStatus.no_recommendation)
示例#4
0
def distribute_recommendations():
    """ Distribute new recommendations as status updates on twitter.
    :return: number of distributed recommendations
    """
    t = Twitter(auth=OAuth(Config.access_token, Config.access_token_secret, Config.api_key, Config.api_secret))
    recs = RecommendationDao.get_new_recommendations()

    number_recs = 0
    for rec in recs:
        number_recs += 1
        try:
            t.statuses.update(status=rec.text, in_reply_to_status_id=rec.userTweet.twitterId)
            RecommendationDao.update_status(rec, Enums.RecommendationStatus.done)
        except Exception as e:

            print(e)
            if "duplicate" in str(e):
                RecommendationDao.update_status(rec, Enums.RecommendationStatus.duplicate)
            else:
                RecommendationDao.update_status(rec, Enums.RecommendationStatus.unable)

    return number_recs