예제 #1
0
def get_retweets_for_tweetids(twt_ids, ids_set):
    """get all retweets for a set of tweets
       INPUT : a list of tweet ids
       OUTPUT: all retweets for each tweet id
    """
    calls_count = 0
    for tid in twt_ids:
        if calls_count < 15:
            #print("    retweets of tweet id ", tid)
            calls_count += 1
            retweet_results = get_retweets(int(tid), 100)
            retweets_list = [rt for rt in retweet_results]
            print("fetched ", len(retweets_list), " retweets")

            if retweets_list:
                write_to_file(retweets_list, tid)
                retweeter_names = []
                del retweeter_names[:]  #initial cleaning
                for res in retweets_list:
                    tweeter_name = res['retweeted_status']['user'][
                        'screen_name']
                    rtwtr_name = res['user']['screen_name']
                    retweeter_names.append(rtwtr_name)
                    print("retweeted by ", rtwtr_name)
                print("original tweeter username: "******"\n")

                #fetch followers of original tweeter
                folr_ids = gfn.get_followers_ids(tweeter_name)
                print(" Fetched {} (followers') twitter ids ..".format(
                    len(folr_ids)))
                screen_names = gfn.get_user_names(folr_ids)
                gfn.write_to_file(screen_names, tweeter_name,
                                  "../data/followers/")

                #compute overlap & hop
                compute_hop1_overlap(screen_names, retweeter_names,
                                     tweeter_name)
        else:
            calls_count = 0
            sleeper(1000)
예제 #2
0
def get_retweets_for_tweetids(twt_ids, ids_set):
    """get all retweets for a set of tweets
       INPUT : a list of tweet ids
       OUTPUT: all retweets for each tweet id
    """
    calls_count = 0
    for tid in twt_ids:
        if calls_count < 15:
            #print("    retweets of tweet id ", tid)
            calls_count += 1
            retweet_results = get_retweets(int(tid), 100)
            retweets_list = [rt for rt in retweet_results]
            print("fetched ", len(retweets_list), " retweets")

            if retweets_list:
                write_to_file(retweets_list, tid)
                retweeter_names = []
                del retweeter_names[:] #initial cleaning
                for res in retweets_list:
                    tweeter_name = res['retweeted_status']['user']['screen_name']
                    rtwtr_name = res['user']['screen_name']
                    retweeter_names.append(rtwtr_name)
                    print("retweeted by ", rtwtr_name)
                print("original tweeter username: "******"\n")

                #fetch followers of original tweeter
                folr_ids = gfn.get_followers_ids(tweeter_name)
                print(" Fetched {} (followers') twitter ids ..".format(len(folr_ids)))
                screen_names = gfn.get_user_names(folr_ids)
                gfn.write_to_file(screen_names, tweeter_name, "../data/followers/")

                #compute overlap & hop
                compute_hop1_overlap(screen_names, retweeter_names, tweeter_name)
        else:
            calls_count = 0
            sleeper(1000)
예제 #3
0
def get_retweets_for_tweetids(twt_ids, twtrIDmap, folr_thresh):
    """To get all retweets for a set of tweets.
       INPUT : a list of tweet ids
       OUTPUT: all retweets for each tweet id
    """
    total_calls_count = 0
    follower_calls = 0
    friends_calls = 0

    for tid in twt_ids:
        if int(twtrIDmap[tid][1]) < int(folr_thresh):               #skip tweeters with huge followers
                print("\n", twtrIDmap[tid][0],"=>", twtrIDmap[tid][1], "=>", str(folr_thresh))
                total_calls_count += 1
                retweet_results = get_retweets(int(tid), 100)
                retweets_list = [rt for rt in retweet_results]
                print("fetched ", len(retweets_list), " retweets")

                if retweets_list:
                    write_to_file(retweets_list, tid)
                    retweeter_names = []
                    retweeter_ids = []
                    retweeter_stats = {}
                    retweeter_stats.clear() #dict cleaning
                    retweeting_time = []
                    del retweeter_names[:] #initial cleaning
                    del retweeter_ids[:]
                    del retweeting_time[:]
                    for res in retweets_list:
                        tweeter_name = res['retweeted_status']['user']['screen_name']
                        tweeter_id = res['retweeted_status']['user']['id']
                        tweeter_folrs = res['retweeted_status']['user']['followers_count']
                        status_count = res['retweeted_status']['user']['statuses_count']
                        following = res['retweeted_status']['user']['friends_count']
                        tweet_time = res['retweeted_status']['created_at']
                        retweet_time = res['created_at']
                        retweet_time = to_datetime(retweet_time)
                        retweet_count = res['retweet_count']
                        rtwtr_name = res['user']['screen_name']
                        retweeter_stats[rtwtr_name] = [res['user']['followers_count'], \
                                                       res['user']['statuses_count'], \
                                                       res['user']['friends_count']]
                        rtwtr_id = res['user']['id']
                        retweeter_names.append(rtwtr_name)
                        retweeter_ids.append(rtwtr_id)
                        retweeting_time.append(retweet_time)
                    print("Original tweeter username: "******"\n")

                    # format tweet time
                    tweet_time = to_datetime(tweet_time)

                    # fetch followers of original tweeter
                    folr_ids, fcal = gfn.get_followers_ids(tweeter_name, follower_calls)
                    follower_calls += fcal
                    print("current value of follower_calls: ", follower_calls)
                    print("Fetched {} (followers') twitter ids ..".format(len(folr_ids)))

                    # compute direct hop
                    L1_overlap, subset_check, disjoint_check = compute_hop1_overlap(retweeter_ids, folr_ids, tweeter_name)
                    print("subset, disjoint: ", subset_check, disjoint_check)

                    if subset_check:
                        tweeter_Vals = [1, tweeter_name, tweet_time, len(retweeter_names), 'Yes', 'No', tweeter_folrs, status_count, following]
                        retweeter_Vals = [retweeter_names, retweeting_time, "-", 'No', L1_overlap, retweeter_stats]

                        ptabled = prettyPrint(tweeter_Vals, retweeter_Vals)
                        output_stats(ptabled)

                        if total_calls_count < 15 and follower_calls < 15:
                            continue
                        else:
                            sleeper(900)
                            follower_calls = 0
                            total_calls_count = 0

                    else:
                        print("Not all retweeters are direct followers of original tweeter.")
                        not_dir_folrs_stats = make_friends_call(retweeter_ids, retweeter_names, folr_ids,
                                                          tweeter_name, tweeter_id, total_calls_count, friends_calls)
                        print("NOT-DIR-FOLRS-STATS:\n", not_dir_folrs_stats)

                        tweeter_Vals = [1, tweeter_name, tweet_time, len(retweeter_names), 'Yes', 'No', tweeter_folrs, status_count, following]
                        retweeter_Vals = [retweeter_names, retweeting_time, "-", 'No', L1_overlap, retweeter_stats]

                        ptabled = prettyTabled(tweeter_Vals, retweeter_Vals, not_dir_folrs_stats)
                        output_stats(ptabled)

                        if total_calls_count < 15 and follower_calls < 15:
                            continue
                        else:
                            sleeper(900)
                            follower_calls = 0
                            total_calls_count = 0

        else:
            continue