Reputation: 11
I am trying to create a Twitter bot using Tweepy that replies to mentions but needs to process the tweet the mention is replying to. I have everything else figured out except how to get the tweet the mention is replying to. I have looked through the documentation several times and have been unable to find a way to do this. Any help is much appreciated.
Upvotes: 1
Views: 591
Reputation: 97
to have your bot reply to a user's screen_name is what I think is what you are asking here. You need to have:
class MyStreamListener(tweepy.StreamListener)
inside the class, function on_status(self, status) and on_error(self, status_code)
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
name = status.user.screen_name
id_str = status.id_str
message = " // < message > //"
reply_tweet = "@" + str(name) + " " + message
api.update_status(reply_tweet, in_reply_to_status_id= id_str)
print(" <tweet received> " + status.text)
print(" tweet sent back > " + reply_tweet)
def on_error(self, status_code):
if status_code == 420:
print("rate limit reached")
return False
i would suggest having a timer in a while loop function as to avoid rate limits
Upvotes: 1