Search code examples
pythontwittertweepytwitter-oauthtwitterapi-python

How to check whether I already replied to a tweet or not?


I am aware of a method in which we can save tweet ids to which we replied in a text file. Then while replying to a new tweet, search in that file, and check whether we already replied to that id or not. If the tweet to which we are replying to already exists in the file, then don't reply. But the problem is by the time this list of ids will grow and and searching will become time consuming.

I am thinking to get tweet ids of all the replies. Then check username of those replies. If it matches with mine, then don't reply.

My question is how to get tweet ids of replies? I am not able to figure out a way to do this using twitter apis and tweepy. Alternate solutions are welcome.


Solution

  • You can simply create a list with the ids you replied to

    replied = [] 
    

    then for each reply:

    replied.append(tweet.id)
    

    When you need to check if the tweet is already replied:

    if tweet.id not in replied:
        #e.g. reply