1

Whenever I create a status stream object I start streaming information from the twitter API. If I want to do a method to stop the stream what would be the way of doing so? The method I need some help with is stopStream() which would stop the twitter stream whenever that method is called.

from tweepy.streaming import StreamListener
    from tweepy import OAuthHandler
    from tweepy import Stream
    import time
    import json
    import csv
    import sys
    import Tweet
    import DatabaseInteractor 
    import twitter_credentials




class StatusStream(StreamListener):

    def __init__(self):

      self.continueStream = True
      super(StatusStream, self).__init__()


      def on_status(self, status):

          print(status.text)
          if(self.continueStream ==False):
            return False 





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

    @staticmethod
    def stopStream():
      self.continueStream = False


auth = OAuthHandler(twitter_credentials.API_KEY,twitter_credentials.API_SECRET_KEY)
auth.set_access_token(twitter_credentials.ACCESS_TOKEN,twitter_credentials.ACCESS_TOKEN_SECRET)
twitterStream = Stream(auth=auth, listener=StatusStream(),tweet_mode='extended')
twitterStream.filter(track=["plumber","visa","bathtub"])
Yamin Himani
  • 77
  • 1
  • 9
  • Related to https://stackoverflow.com/questions/33498975/unable-to-stop-streaming-in-tweepy-after-one-minute – JeffProd Jun 13 '20 at 08:21

0 Answers0