Exemplo n.º 1
0
def predict_tweet(app_user_email, tweet_id):
    aws_conn = SQLConnection.AWSConnection()
    twit_conn = TwitterConnection.TwitterConnection()
    time_of_search = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    # from this point on use status
    status = twit_conn.get_tweet(tweet_id)
    print('GOT STATUS', status)

    # if tweet search already in progress
    with label_tweet_task_lock:
        if app_user_email in running_tweet_tasks:
            for (cur_screen_name, cur_tweet_id, cur_text,
                 cur_time) in running_tweet_tasks[app_user_email]:
                if cur_tweet_id == status['id']:
                    return {'status': 'already in progress'}
            add_tweet_to_running_tasks(app_user_email, status['screen_name'],
                                       status['id'], status['text'],
                                       time_of_search)
        else:
            running_tweet_tasks[app_user_email] = [
                (status['screen_name'], status['id'], status['text'],
                 time_of_search)
            ]

    print(running_tweet_tasks)
    try:
        # checks if tweet has already been searched and predicted before
        previous_tweet = aws_conn.get_searched_tweet_by_id(
            tweet_id)  #status or False

        if previous_tweet is not None:
            aws_conn.insert_searched_tweet(app_user_email, previous_tweet[1],
                                           previous_tweet[2],
                                           previous_tweet[3], time_of_search)
            return {'status': 'tweet already searched'}

        likers = twit_conn.get_liked_list(tweet_id)

        user_objects_likers = twit_conn.get_user_objects(likers)
        print('number of likers ' + str(len(user_objects_likers)))
        for liker in user_objects_likers:
            does_user_exist = aws_conn.get_twitter_user(
                liker.screen_name.lower())
            if does_user_exist is None:
                get_tweets(liker, aws_conn)
            else:
                continue
        aws_conn.insert_searched_tweet(app_user_email, status['id'],
                                       status['screen_name'], status['text'],
                                       time_of_search)
        aws_conn.insert_tweet_likes(likers, tweet_id)
    finally:
        remove_tweet_from_running_tasks(app_user_email, status['screen_name'],
                                        status['id'], status['text'],
                                        time_of_search)

    return {'status': 'new tweet'}
Exemplo n.º 2
0
def get_searched_users(app_user_email):
    aws_conn = SQLConnection.AWSConnection()
    searched_users = []
    if app_user_email in running_user_tasks:
        for task in running_user_tasks[app_user_email]:
            searched_users.append(
                (task[0], None, str(task[1]), None, None, 'Pending...'))
    searched_users.extend(aws_conn.get_searched_twitter_users(app_user_email))
    # print('******SEARCHED USERS****** ' + str(searched_users))
    return searched_users
Exemplo n.º 3
0
def get_searched_tweets(app_user_email):
    aws_conn = SQLConnection.AWSConnection()
    searched_tweets = []
    with label_tweet_task_lock:
        if app_user_email in running_tweet_tasks:
            # (status['screen_name'], status['id'], time_of_search)
            in_progress = running_tweet_tasks[app_user_email]
            for tweet_task in in_progress:
                searched_tweets.append(
                    (app_user_email, tweet_task[1], tweet_task[0],
                     tweet_task[2], tweet_task[3], 'In progress...'))
    db_tweets = aws_conn.get_searched_tweets_by_email(app_user_email)
    searched_tweets.extend(db_tweets)
    # print('******SEARCHED TWEETS****** ' + str(searched_tweets))
    return searched_tweets
Exemplo n.º 4
0
def predict_user_tweepy(screen_name, app_user_email):
    twit_conn = TwitterConnection.TwitterConnection()
    aws_conn = SQLConnection.AWSConnection()
    time_of_search = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    add_to_existing = False
    with label_user_task_lock:
        if app_user_email in running_user_tasks:
            for (cur_screen_name,
                 cur_time) in running_user_tasks[app_user_email]:
                if cur_screen_name == screen_name:
                    return {'status': 'already in progress'}
            add_to_existing = True
        else:
            running_user_tasks[app_user_email] = [(screen_name, time_of_search)
                                                  ]

    if add_to_existing:
        add_label_user_task_to_queue(app_user_email, screen_name,
                                     time_of_search)

    try:
        cur_user = aws_conn.get_twitter_user(screen_name)

        if cur_user:
            aws_conn.insert_searched_twitter_user(app_user_email, screen_name,
                                                  time_of_search)
            return {'status': 'user already scraped'}

        user_obj = twit_conn.get_user_objects([screen_name])[0]

        get_tweets_tweepy(user_obj, aws_conn)

        aws_conn.insert_searched_twitter_user(app_user_email, screen_name,
                                              time_of_search)
        print('WROTE SEARCHED')
    finally:
        # removes the current task from the user tasks
        remove_label_user_task_from_queue(app_user_email, screen_name,
                                          time_of_search)
    return {'status': 'added new user'}
Exemplo n.º 5
0
def create_new_user(email):
    aws_conn = SQLConnection.AWSConnection()
    aws_conn.create_user_profile(email)
    return
Exemplo n.º 6
0
def get_tweet_likes(tweet_id):
    aws_conn = SQLConnection.AWSConnection()
    tweet_like_info = aws_conn.get_tweet_like_info(tweet_id)
    return tweet_like_info