挖掘Python中两个日期之间的推文

时间:2016-10-08 17:17:02

标签: python twitter

我想在特定时间内为两个关键字发布推文。我目前有以下代码,但是我如何添加以便只在两个日期之间发布推文? (10/03/2016 - 10/07/2016)谢谢!

#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#Variables that contains the user credentials to access Twitter API 
access_token = "ENTER YOUR ACCESS TOKEN"
access_token_secret = "ENTER YOUR ACCESS TOKEN SECRET"
consumer_key = "ENTER YOUR API KEY"
consumer_secret = "ENTER YOUR API SECRET"


#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):

    def on_data(self, data):
        print data
        return True

    def on_error(self, status):
        print status


if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    stream.filter(track=['python', 'javascript', 'ruby'])

1 个答案:

答案 0 :(得分:1)

你不能。看看this question,这是你能得到的最接近的。

Twitter API不允许按时间搜索。琐碎的是,你可以做的是在Python中获取推文并查看他们的时间戳,但效率非常低。