Python 从特定时间的主题标签获取所有推文

Python getting all tweets from a hashtag with a specific time

我正在编写代码。它应该从具有特定时间的主题标签中获取所有推文,并将其写入终端或 JSON 文件或文本文件,但我的程序只获取一条推文并将其写入所有其他推文。例如:

我想要的输出:

*一个 *乙 *C

我得到的输出:

*一个 *一种 *A

我该如何解决这个问题?

这是我的代码:

def date_range(start,end):
   current = start
   while (end - current).days >= 0:
      yield current
      current = current + datetime.timedelta(seconds=1)  

class TweetListener(StreamListener):
    def on_status(self, status):
        #api = tweepy.API(auth_handler=auth)
        #status.created_at += timedelta(hours=900)

        startDate = datetime.datetime(2013, 6, 30)
        stopDate = datetime.datetime(2013, 10, 30)
        for date in date_range(startDate,stopDate):
            status.created_at = date
            print ("tweet " + str(status.created_at) +"\n")
            print (status.text + "\n" )
            # You can dump your tweets into Json File, or load it to your database

stream = Stream(auth, TweetListener(), secure=True, )
t = "#twitter" # You can use different hashtags
stream.filter(track=[t])

您无法流式传输过去日期的推文。推文流仅包含在您的流打开时发布的推文。如果您想要旧推文,请使用 search/tweets endpoint. However, that will only return tweets from the last week or so. It will not return tweets, as in your example, from 4 years ago. To do that you will need to pay for a service such as Gnip.