zoukankan      html  css  js  c++  java
  • Python 提取Twitter转发推文的元素(比方username)

    CODE:

    #!/usr/bin/python 
    # -*- coding: utf-8 -*-
    
    '''
    Created on 2014-7-24
    @author: guaguastd
    @name: extract_retweet_attributions.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 twitter_search
        
        # import extract_retweet_id
        from tweet import extract_retweet_id, get_rt_attributions
        
        while 1:
            query = raw_input('
    Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
            
            if query == 'exit':
                print 'Successfully exit!'
                break
            
            search_results = twitter_search(twitter_api, query, max_results=1)
            #print search_results,
            
            # Get the retweet id
            retweets_id = extract_retweet_id(search_results)
            #print retweets_id,
            
            # Get the retweet attribution
            for rid in retweets_id:
                tweet = twitter_api.statuses.show(_id=rid)
                print get_rt_attributions(tweet)
                print

    RESULT:

    Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Core Python
    Length of statuses 60
    
    [u'ritzylivingwage']


  • 相关阅读:
    SQL随记(四)
    一些有用的方法命令
    导航目录
    HTML中       等6种空白空格的区别
    MyBatis学习资料
    Spring Cloud资料
    聚类算法对比
    Spark 读取HBase数据
    ZooKeeper设置ACL权限控制
    大数据工具选择
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5067834.html
Copyright © 2011-2022 走看看