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)

返回栏目页:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

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

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索10
, total
, be
, friend
Python交集
mysql 交集 并集 差集、sql 交集 并集 差集、交集 并集 差集、交集 并集 差集 补集、java 交集 并集 差集,以便于您获取更多的相关知识。

时间: 2024-10-25 04:07:52

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

Python如何获取Twitter搜索结果

#!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-06-28 @author: guaguastd @name: search_for_tweet.py ''' if __name__ == '__main__': import json # import search from search import search_for_tweet # import login, see http://blog.csdn.net/

JSONP获取Twitter和Facebook文章数的具体步骤

 这篇文章主要介绍了JSONP获取Twitter和Facebook文章数的方法,需要的朋友可以参考下 原文是使用的Twitter和Facebook,因为国内被强,所以我觉得有用的是里面一个获取JSONP的那个工具类.    我很头疼的是,许多流行的 APIs 已经要求身份验证才能获取信息.    既然我可以访问到这些页面并取得信息,那为什么我不使用一些简单的代码来获取并跳过验证这一步呢?  我认为Twitter和Facebook要求身份验证来获取文章的数量,但事实证明你可以通过JSONP来获取这

微博爬虫-求助。用python爬取微博用户的粉丝列表及粉丝的粉丝列表

问题描述 求助.用python爬取微博用户的粉丝列表及粉丝的粉丝列表 急需一份能爬取微博用户的粉丝列表及对应粉丝的粉丝列表搭建一个实验平台,由于自己编程能力太弱,所以希望好心人能给一份相应的python代码(其他语言编写的能运行的也可),在线等,急求! 解决方案 Python:获取新浪微博用户的收听列表和粉丝列表微博粉丝 解决方案二: python爬取糗百 模式不变 改一下正则就可以 也可以用sqllite保存 .正则自己网上看一下就回了 解决方案三: urllib请求页面获取response

oracle-linux环境下,用python怎么取得指定用户的环境变量

问题描述 linux环境下,用python怎么取得指定用户的环境变量 在linux环境下,例如当前用户是root,通过os.environ取到的是当前用户的环境变量. 当时我想去其他用户的环境变量,例如oracle用户,有什么办法? 谢谢 解决方案 这个需要你su先切换用户,然后再获取对应环境变量 解决方案二: 其他用户环境变量直接读配置文件获取得了.对应用户目录下 .bashrc . .bash_profile

python入门基础之用户输入与模块初认识_python

一.注释 当前行注释:# 被注释内容 多行注释:""" 被注释内容 """ 二.用户输入 #!/usr/bin/env python #_*_coding:utf-8_*_ #name = raw_input("What is your name?") #only on python 2.x name = input("What is your name?") print("Hello "

编写Ruby脚本来对Twitter用户的数据进行深度挖掘_ruby专题

Twitter以及一些API 尽管早期的网络涉及的是人-机器的交互,但现在的网络已涉及机器-机器之间的交互,这种交互是使用web服务来支持的.大部分受欢迎的网站都有这样的服务存在--从各种各样的Google服务到LinkedIn.Facebook和Twitter等.通过web服务创建的API,外部的应用可以查询或是操纵网站上的内容. web服务可以使用多种方式来实现.目前最流行的做法之一是表述性状态转移(Representational State Transfe, REST).REST的一种实

先获取更多用户 创业前需要知道的5件事情

中介交易 SEO诊断 淘宝客 云主机 技术大厅 编者:本文作者Vik Singh为Infer公司的创始人兼CEO.Infer刚刚获得了1000万美元的A轮融资,投资方为Redpoint Ventures.他们为Box.Jive.Nitro.Tableau和Zendesk等公司提供数据应用服务. 过去的两年中,我一直在经营我的企业.而在这段过程中,我也获得了宝贵的经验,知道了应该如何经营企业.以下是5个每个创业者都应该知道的事情: 在一段时间内先专注于80%的事情 不要在刚一开始就试图开发出很多核

Twitter用户评论可提高电视节目收视率

新浪科技讯 北京时间8月7日凌晨消息,市场研究机构尼尔森(Nielsen)最新调查数据显示,Twitter用户在收看电视节目时发布的相关评论推文能够提高电视节目收视率.尼尔森对200多档黄金时段的电视节目进行分析,研究发现,Twitter用户在发布有关某一电视节目的评论推文时,推文数量的增加能使该节目在近三分之一的播放时间内收视率得到提升.反之,该节目的收视率越高, 就会有越多的Twitter用户发布相关评论推文.这是尼尔森首次在Twitter用户行为与电视节目收视率之间建立起直接联系,或能让T

Twitter用户实时评论可提高电视节目收视率

 2013年8月7日市场研究公司尼尔森公布最新报告称,Twitter用户可提高电视节目的收视率,原因是这些用户会在收看电视节目的同时发布实时共享评论. 在对200多个黄金时段电视节目进行分析后,尼尔森得出的结论是,有关一部电视剧的Twitter消息数量的激增将可在近三分之一的时间里提高收视率:反之亦然:越多观众收看一部剧集,就会有越多Twitter用户发布实时评论. 这份报告标志着尼尔森首次在Twitter用户活动与电视节目收视率之间建立起直接的联系,这可能有助于Twitter吸收更多的广告主,