You are on page 1of 1

import tweepy

from tweepy import OAuthHandler


from tweepy import Stream
from tweepy.streaming import StreamListener
import time

consumer_key = 'your consumer key'


consumer_secret = 'your consumer_secret'
access_token = 'your access_token'
access_secret = 'your access_secret'

auth = OAuthHandler(consumer_key, consumer_secret)


auth.set_access_token(access_token, access_secret)

#api = tweepy.API(auth)

class MyListener(StreamListener):

def on_data(self, data):


try:
with open('collect.json','a') as f:
f.write(data)
return True
except BaseException as e:
print("Error on_data: %s" % str(e))
time.sleep(5)
return True

def on_error(self, status):


print(status)
return True

twitter_stream = Stream(auth, MyListener())


twitter_stream.filter(track=['#budget2020'])
#twitter_stream.filter(track=['#place the hashtags seperated by commas'])
#twitter_stream.filter(track=['#a','#b']) in this way

You might also like