Python Twitter bot part 5

Python Twitter bot part 5

                 Python Twitter Bot Part 5                                         

Hey guys, Welcome to the part 5 of twitter bot. As we have learned how to connect twitter API and python ide and also how to create some twitter bots in the previous articles. Now, let us create a follow back followers twitter bot. Sometimes it is very hard to follow each and every twitter follower back when the followers are hundreds or thousands and some times even in millions. That is where this twitter bot comes in handy. So, lets get into the coding part.

Code of Follow back followers twitter bot:

import tweepy
#enter your keys here
#enter your keys here
#to establish connection
#assigned our twitter home timeline information to the variable public_tweets

def limit_handler(cursor):
except tweepy.RateLimitError:

#The above limit_handler function is used because when the followers are many, then continously getting back to twitter API to follow each person makes the twitter server to get hang. So, we use the function to set a time limit between each iteration, so that the program sleeps for some mentioned time. Here the function while going through every iteration, it checks whether we are getting an RateLimitError or not, if we do then it sleeps for 300ms and if not the next iteration goes on.

for follower in limit_handler(tweepy.Cursor(api.followers).items()):
if"xyz": #this is to follow certain follower, we can even mention multiple followers usernames. Here we considered xyz as an username for understanding purpose.

If we want to follow back every follower then, we can use:

for follower in limit_handler(tweepy.Cursor(api.followers).items()):

We will learn about auto like twitter bot in the next article.