In here, Limit tweepy stream to a specific number, I tried to stop a streaming script using tweepy but kept getting an error. I tried fixing the error as some people may have suggested but no luck.
I thought of another method of possibly terminating the script based on a the number of printed outputs. What I did is take the previous code and put into a function:
def streamer(location):
## same code here ##
twitterStream.filter(locations=[\location) ## changed to match function##
Then I would call the function (i.e. streamer(LA)
) where LA is predefined with a set of coordinates.
My question: Is it possible to terminate the function streamer
based on the number it outputs without changing the function itself (due to persisting error)?
you could use
quit()
but that also terminates the whole session.You also need to add your streamdata to a variable somewhere. If I am correct you will get a constant stream of Json items, so just add them to a list and then use the length of the list. Then use twitterstream.disconnect() if you got your amount of outputs.