码迷,mamicode.com
首页 > 编程语言 > 详细

Python 提取Twitter特定话题中转载tweet的用户

时间:2014-07-08 19:09:48      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:twitter   数据挖掘   

CODE:

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

'''
Created on 2014-7-7
@author: guaguastd
@name: user_retweet_statuses.py
'''
    
if __name__ == '__main__':

    # 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 search
    from search import search_for_tweet
    
    # import tweet
    from tweet import extract_retweet_id
    
    # pip install prettytable
    #from prettytable import PrettyTable
    
    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)
        retweet_ids = extract_retweet_id(statuses)
      
        for retweet_id in retweet_ids:
            _retweets = twitter_api.statuses.retweets(id=retweet_id)
            print [r['user']['screen_name'] for r in _retweets]

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou
Length of statuses 100
Length of statuses 100
[u'kissmyasshton_']
[u'idkdallasbae', u'Catarina5SOS1D', u'ElenaBomerC']
[u'Manu_19x']
[u'idkdallasbae', u'Catarina5SOS1D', u'ElenaBomerC']
[u'xrayfux']
[u'paynashton', u'gellystyles']
[u'paynashton', u'gellystyles']
[u'idkdallasbae', u'Catarina5SOS1D', u'ElenaBomerC']
[u'soulfullybutera']
[u'drewxhemmo']
[u'drewxhemmo']
[u'weirdbutera']
[u'demisbearx']
[u'KidrauhlOGrande']
[u'LOnarryfeelsVE']
[u'lesxfleurs']
[u'flowerlyariana']
[u'findanusername']
[u'osnapitzjasmin']
[u'BlEBERSKING', u'JILEYFCKN']
[u'SASSYMCCANN']
[u'ButeraKisss']
[u'BlEBERSKING', u'JILEYFCKN']
[u'michaelscobain']
[u'versxce5sos']
[u'jdbftvamps_']
[u'aridelreys']
[u'GrandeAmaze']
[u'arianastralia']
[u'heelsbutera']
[u'cliffords_taco']
[u'snowinboca']
[u'avonkitties']
[u'ohsnapitzisaa']
[u'Daa_Biebss']
[u'PinkUnicornAri']

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): 


Python 提取Twitter特定话题中转载tweet的用户,布布扣,bubuko.com

Python 提取Twitter特定话题中转载tweet的用户

标签:twitter   数据挖掘   

原文地址:http://blog.csdn.net/guaguastd/article/details/37490993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!