I am currently trying to stream live tweets to my console of a specific user using the tweepy library (twitter api v2). I have found documentation for key words or hashtags but not to filter by the user who tweeted. Anyone know how I can add a rule to filter all tweets by say @elonmusk?
client = tweepy.Client(keys.BEARER_TOKEN, keys.API_KEY, keys.API_KEY_SECRET, keys.ACCESS_TOKEN, keys.ACCESS_TOKEN_SECRET)
auth = tweepy.OAuth1UserHandler(keys.API_KEY,keys.API_KEY_SECRET, keys.ACCESS_TOKEN, keys.ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
class MyStream(tweepy.StreamingClient):
def on_tweet(self, tweet):
print(tweet.text)
time.sleep(0.2)
stream = MyStream(bearer_token=keys.BEARER_TOKEN)
stream.add_rules({'from: elonmusk'})
print(stream.get_rules())
stream.filter()
2
Answers
ANSWER: I used the twarc CLT to solve this issue.
Steps taken to add a rule to specify tweets by a user: