Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-7-30
@author: guaguastd
@name: friends_followers_analyzer.py
'''

if __name__ == '__main__':
    
    # import json
    #import json
    
    # import search
    from search import search_for_tweet
    
    # import get_friends_followers_ids
    from user import get_friends_followers_ids, setwise_friends_followers_analysis
    
    # import login, see http://blog.csdn.net/guaguastd/article/details/31706155
    from login import twitter_login

    # get the twitter access api
    twitter_api = twitter_login()
    
    # import twitter_text
    import twitter_text
    
    while 1:
        query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
        
        if query == 'exit':
            print 'Successfully exit!'
            break
        
        statuses = search_for_tweet(twitter_api, query) 
        ex = twitter_text.Extractor(statuses)     
        
        screen_names = ex.extract_mentioned_screen_names_with_indices()
        screen_names = [screen_name['screen_name']
                        for screen_name in screen_names]
                
        for screen_name in screen_names:
            #print json.dumps(screen_names, indent=1)  
            friends_ids, followers_ids = get_friends_followers_ids(twitter_api,
                                                                   screen_name=screen_name,
                                                                   friends_limit=10,
                                                                   followers_limit=10)
            setwise_friends_followers_analysis(screen_name, friends_ids, followers_ids)

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou
Length of statuses 30
Encountered 401 Error (Not Authorized)
Fetched 0 total friends ids for mcnasty_super
Encountered 401 Error (Not Authorized)
Fetched 0 total followers ids for mcnasty_super
mcnasty_super is following 0
mcnasty_super is being followed by 0
0 of 0 are not following mcnasty_super back
0 of 0 are not being followed back by mcnasty_super
mcnasty_super has 0 mutual friends
Fetched 5000 total friends ids for Justina25ita
Fetched 5000 total followers ids for Justina25ita
Justina25ita is following 10
Justina25ita is being followed by 10
6 of 10 are not following Justina25ita back
6 of 10 are not being followed back by Justina25ita
Justina25ita has 4 mutual friends
BadStatusLine encountered. Continuing.
Fetched 5000 total friends ids for CarolRibTorres
Fetched 5000 total followers ids for CarolRibTorres
CarolRibTorres is following 10
CarolRibTorres is being followed by 10
1 of 10 are not following CarolRibTorres back
1 of 10 are not being followed back by CarolRibTorres
CarolRibTorres has 9 mutual friends
Fetched 5000 total friends ids for CarolRibTorres
Fetched 5000 total followers ids for CarolRibTorres
CarolRibTorres is following 10
CarolRibTorres is being followed by 10
1 of 10 are not following CarolRibTorres back
1 of 10 are not being followed back by CarolRibTorres
CarolRibTorres has 9 mutual friends
Fetched 5000 total friends ids for JustinBieber
JustinBieber is following 10
JustinBieber is being followed by 10
10 of 10 are not following JustinBieber back
10 of 10 are not being followed back by JustinBieber
JustinBieber has 0 mutual friends
Fetched 5000 total followers ids for JustinBieber
Fetched 2818 total friends ids for Janoskians
Fetched 5000 total followers ids for Janoskians
Janoskians is following 10
Janoskians is being followed by 10
10 of 10 are not following Janoskians back
10 of 10 are not being followed back by Janoskians
Janoskians has 0 mutual friends
Fetched 5000 total friends ids for 5SOS
Fetched 5000 total followers ids for 5SOS
5SOS is following 10
5SOS is being followed by 10
10 of 10 are not following 5SOS back
10 of 10 are not being followed back by 5SOS
5SOS has 0 mutual friends
Fetched 63 total friends ids for shots
Fetched 5000 total followers ids for shots
shots is following 10
shots is being followed by 10
10 of 10 are not following shots back
10 of 10 are not being followed back by shots
shots has 0 mutual friends
Fetched 5000 total friends ids for CarolRibTorres
Fetched 5000 total followers ids for CarolRibTorres
CarolRibTorres is following 10
CarolRibTorres is being followed by 10
1 of 10 are not following CarolRibTorres back
1 of 10 are not being followed back by CarolRibTorres
CarolRibTorres has 9 mutual friends
Fetched 5000 total friends ids for JustinBieber
Fetched 5000 total followers ids for JustinBieber
JustinBieber is following 10
JustinBieber is being followed by 10
10 of 10 are not following JustinBieber back
10 of 10 are not being followed back by JustinBieber
JustinBieber has 0 mutual friends
Fetched 2818 total friends ids for Janoskians
Fetched 5000 total followers ids for Janoskians
Janoskians is following 10
Janoskians is being followed by 10
10 of 10 are not following Janoskians back
10 of 10 are not being followed back by Janoskians
Janoskians has 0 mutual friends


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值