根据关键字,用户名和日期间隔搜索推特流

时间:2015-02-04 09:19:48

标签: python-2.7 twitter tweetstream

我想编写一个程序,可以根据关键字,用户名和日期范围从Twitter中提取推文。我使用Tweepy编写程序来从Streaming API中提取推文。目前,它根据关键字OR用户名提供推文。

我想更改程序以包含过滤标准:关键字和用户名AND date_range。我该如何修改程序?

使用的Python版本:2.7

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

# Removed my authentication parameters because of confidentiality
consumer_key=
consumer_secret=
access_token=
access_token_secret=

class StdOutListener(StreamListener):
    def on_data(self, data):
        saveFile= open('save_tweets.txt','a')
        saveFile.write(data)
        saveFile.write('\n')
        return True

    def on_error(self, status):
        print(status)

    def on_limit(self, track):
        return

    def on_timeout(self):
        print ('time out')
        return

    def on_disconnect(self, notice):
        print (notice)
        return    
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
track_list=['art','gallery']
follow_list=['70100659','12804422']
stream.filter(track=track_list, follow=follow_list)

0 个答案:

没有答案