twitter.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:cjworkbench 作者: CJWorkbench 项目源码 文件源码
def get_new_tweets(wfm, querytype, query, old_tweets):

        # Authenticate with "app authentication" mode (high rate limit, read only)
        consumer_key = os.environ['CJW_TWITTER_CONSUMER_KEY']
        consumer_secret = os.environ['CJW_TWITTER_CONSUMER_SECRET']
        auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
        api = tweepy.API(auth)

        # Only get last 100 tweets, because that is twitter API max for single call
        if querytype == Twitter.QUERY_TYPE_USER:
            tweetsgen = api.user_timeline(query, count=200)
        else:
            tweetsgen = api.search(q=query, count=100)

        # Columns to retrieve and store from Twitter
        # Also, we use this to figure ou the index the id field when merging old and new tweets
        cols = ['id', 'created_at', 'text', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'retweeted',
                'retweet_count', 'favorited', 'favorite_count', 'source']

        tweets = [[getattr(t, x) for x in cols] for t in tweetsgen]
        table = pd.DataFrame(tweets, columns=cols)
        return table


    # Combine this set of tweets with previous set of tweets
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号