Ignoring Retweets When Streaming Twitter Tweets
I am trying to run a simple script that will stream live Tweets. Several attempts to filter out retweets have been unsuccessful. I still get manual retweets (with the text 'RT @')
Solution 1:
What you could do is create another function to call inside of the on_status
in your StreamListener
. Here is something that worked for me:
defanalyze_status(text):
if'RT'in text[0:3]:
print("This status was retweeted!")
print(text)
else:
print("This status was not retweeted!")
print(text)
classMyStreamListener(tweepy.StreamListener):
defon_status(self, status):
analyze_status(status.text)
defon_error(self, status_code):
print(status_code)
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth=twitter_api.auth, listener=myStreamListener)
myStream.filter(track=['Trump'])
That yields the following:
This status was not retweeted!
@baseballcrank @seanmdav But they won't, cause Trump's name is on it. I can already hear their stupidity, "I hate D…
This status was retweeted!
RT @OvenThelllegals: I'm about to end the Trump administration with a single tweet
This status was retweeted!
RT @kylegriffin1: FLASHBACK: April 2016
SAVANNAH GUTHRIE: "Do you believe in raising taxes on the wealthy?"
TRUMP: "I do. I do. Inc…
This is not the most elegant solution, but I do believe it addresses the issue that you were facing.
Post a Comment for "Ignoring Retweets When Streaming Twitter Tweets"