Python 查找Twitter中特定话题中最流行(转载最多)的10个Tweet

CODE:

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

'''
Created on 2014-7-21
@author: guaguastd
@name: find_popular_tweets.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 find_popular_tweets
    
    # 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)
        tweets = find_popular_tweets(twitter_api, statuses)
        
        # Slice off the first 10 from the sorted results and display each item in the tuple
        pt = PrettyTable(field_names=['Retweet_count', 'Text'])
        [pt.add_row(row) for row in sorted(tweets, reverse=True)[:10]]
        pt.max_width['Text'] = 50
        pt.align = 'l'
        print pt

RESULT:


Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Google
Length of statuses 100
Length of statuses 199
+---------------+----------------------------------------------------+
| Retweet_count | Text                                               |
+---------------+----------------------------------------------------+
| 25352         | RT @Michael5SOS: 5 MINUTES TILL GOOGLE STREAM 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值