zoukankan      html  css  js  c++  java
  • Python 查找Twitter中特定话题中最流行的10个转发Tweet

    CODE:

    #!/usr/bin/python 
    # -*- coding: utf-8 -*-
    
    '''
    Created on 2014-7-4
    @author: guaguastd
    @name: find_popular_retweets.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 popular_retweets
        
        # pip install prettytable
        from prettytable import PrettyTable
        
        while 1:
            query = raw_input('
    Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
            
            if query == 'exit':
                print 'Successfully exit!'
                break
            
            statuses = search_for_tweet(twitter_api, query)
            retweets = popular_retweets(statuses)
            
            # Slice off the first 10 from the sorted results and display each item in the tuple
            pt = PrettyTable(field_names=['Count', 'Screen Name', 'Text'])
            [pt.add_row(row) for row in sorted(retweets, reverse=True)[:10]]
            pt.max_width['Text'] = 50
            pt.align = 'l'
            print pt

    RESULT:

    Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou
    Length of statuses 30
    +-------+----------------+----------------------------------------------------+
    | Count | Screen Name    | Text                                               |
    +-------+----------------+----------------------------------------------------+
    | 2     | xmlovex        | RT @xmlovex: #MentionSomeoneImportantForYou        |
    |       |                | @purpledrauhl_23                                   |
    | 1     | thuggie_salma  | RT @thuggie_salma: "@KillahPimpp:                  |
    |       |                | #MentionSomeoneImportantForYou @thuggie_salma"     |
    |       |                | baeee 

  • 相关阅读:
    Java基础50道经典练习题(23)——求岁数
    Java基础50道经典练习题(22)——递归求阶乘
    团队第一阶段冲刺04
    团队第一阶段冲刺03
    团队第一阶段冲刺02
    团队第一阶段冲刺01
    软件工作进度01
    软团队项目01之电梯演讲视频
    团队项目1
    C语言动静态链接库使用(笔记)
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6999447.html
Copyright © 2011-2022 走看看