Python 获取Twitter用户的所有的friends和followers

CODE:

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

'''
Created on 2014-7-29
@author: guaguastd
@name: friends_followers_fetch.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

    # 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)
            print json.dumps(friends_ids, indent=1)
            print json.dumps(followers_ids, indent=1)

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou
Length of statuses 36
Fetched 1998 total friends ids for KaJoe243
Fetched 1055 total followers ids for KaJoe243
[
 1422600199,
 458688949,
 1161253873,
 1169815322,
 776404981,
 1592054046,
 747340094,
 631001110,
 333957305,
 770281080
]
[
 244565875,
 804283975,
 529456713,
 2482515389,
 833212254,
 2723007131,
 2601424506,
 823550654,
 2591080621,
 2719436949
]
Fetched 277 total friends ids for Boninajenny
Fetched 157 total followers ids for Boninajenny
[
 2159357795,
 213748275,
 262804580,
 820250366,
 1713397874,
 559150316,
 972223820,
 500760841,
 598357813,
 752105156
]
[
 841258999,
 2721645597,
 636955955,
 339051763,
 319816176,
 559150316,
 820250366,
 1524500682,
 2657351222,
 702425326
]
Fetched 1998 total friends ids for KaJoe243
Fetched 1055 total followers ids for KaJoe243
[
 1422600199,
 458688949,
 1161253873,
 1169815322,
 776404981,
 1592054046,
 747340094,
 631001110,
 333957305,
 770281080
]
[
 244565875,
 804283975,
 529456713,
 2482515389,
 833212254,
 2723007131,
 2601424506,
 823550654,
 2591080621,
 2719436949
]
Fetched 277 total friends ids for Boninajenny
Fetched 157 total followers ids for Boninajenny
[
 2159357795,
 213748275,
 262804580,
 820250366,
 1713397874,
 559150316,
 972223820,
 500760841,
 598357813,
 752105156
]
[
 841258999,
 2721645597,
 636955955,
 339051763,
 319816176,
 559150316,
 820250366,
 1524500682,
 2657351222,
 702425326
]
Fetched 277 total friends ids for Boninajenny
Fetched 157 total followers ids for Boninajenny
[
 2159357795,
 213748275,
 262804580,
 820250366,
 1713397874,
 559150316,
 972223820,
 500760841,
 598357813,
 752105156
]
[
 841258999,
 2721645597,
 636955955,
 339051763,
 319816176,
 559150316,
 820250366,
 1524500682,
 2657351222,
 702425326
]
Fetched 277 total friends ids for Boninajenny
Fetched 157 total followers ids for Boninajenny
[
 2159357795,
 213748275,
 262804580,
 820250366,
 1713397874,
 559150316,
 972223820,
 500760841,
 598357813,
 752105156
]
[
 841258999,
 2721645597,
 636955955,
 339051763,
 319816176,
 559150316,
 820250366,
 1524500682,
 2657351222,
 702425326
]
Fetched 359 total friends ids for SrhGV
BadStatusLine encountered. Continuing.
[
 1175105167,
 777552968,
 560252027,
 2524468307,
 2649629004,
 261332366,
 2601711740,
 1941138769,
 407189800,
 2554569862
]
[
 1175105167,
 1375314614,
 1541598176,
 1223010188,
 2713154950,
 1189139196,
 1541577548,
 1541607992,
 440873116,
 2439750032
]
Fetched 238 total followers ids for SrhGV
Fetched 196 total friends ids for PaulaAV2
Fetched 248 total followers ids for PaulaAV2
[
 188478643,
 840767317,
 2540664564,
 1176337274,
 2192464466,
 531881654,
 492399548,
 2596888296,
 228811123,
 357133822
]
[
 2174949662,
 374750493,
 267452652,
 863777972,
 1511594922,
 1255483015,
 2528828622,
 840767317,
 437918534,
 2596888296
]

Python 获取Twitter用户的所有的friends和followers

时间: 2024-10-11 09:08:23

Python 获取Twitter用户的所有的friends和followers的相关文章

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 ge

Python 提取Twitter用户的Tweet

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-31 @author: guaguastd @name: harvest_user_tweet.py ''' if __name__ == '__main__': # import json import json # import search from search import search_for_tweet # import harvest_use

Python 爬行Twitter用户的Friendship图

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-1 @author: guaguastd @name: crawing_friendship_graph.py ''' if __name__ == '__main__': # import json #import json # import search from search import search_for_tweet # import get_f

Python 获取Facebook用户的Friends的爱好

Code: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-11 @author: guaguastd @name: friends_like_query.py ''' # impot login from login import facebook_login # import helper from helper import pp # access to facebook facebook_api = face

Python 分析Twitter用户喜爱的推文

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-5 @author: guaguastd @name: analyze_favorite_tweet.py ''' if __name__ == '__main__': # import json #import json # import search from search import search_for_tweet # import get_fri

Python 获取Facebook用户与其有共同爱好的Friends

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: common_friends_finding.py ''' # impot login from login import facebook_login # import helper #from helper import pp # import PrettyTable from prettytab

Python 获取Facebook用户的Friends的爱好中的Top10

CODE; #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: friends_popular_likes.py ''' # impot login from login import facebook_login # import helper from helper import pp # calculating the most popular likes

Python 获取Facebook用户Friends的爱好类别中的Top10

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: friends_popular_category.py ''' # impot login from login import facebook_login # import helper #from helper import pp # calculating the most popular ca

Python获取豆瓣用户读过的书

好久好久不写博客了,最近也光顾着玩了,前几天跟导师联系了一下毕设的事,要再爬点东西,想了想,就拿豆瓣图书练练手,爬一下某个用户读过的书(当然也可以好多用户或者其他信息),由于豆瓣提供了API,所以首先想到用API,图书API地址:https://developers.douban.com/wiki/?title=book_v2,看了看,好像没有获取用户读过的书之类的,擦亮眼再看看,有一个获取某用户所有图书收藏信息,那这个到底是不是呢,试一下就知道了. 那个接口里有个参数status,表示收藏状态