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 

  • 相关阅读:
    solr7.7.0 添加core (二)
    centos 安装solr7.7+tomcat8.5.31+jdk1.8 环境搭建(一)
    springboot 切面编程 日志模块
    Mysql 优化
    mysql查询某个字段中是否有重复的值
    php for循环字母
    layui.table.toolbar里的内容加判断
    phpmyadmin 导入大文件配置
    解决laravel5.2 使用ajax时的 VerifyCsrfToken问题
    火狐浏览器禁止缓存
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6999447.html
Copyright © 2011-2022 走看看