Python Twitter Bot – Auto Follow, Unfollow, Favorite, Retweet!
Learn everything about python twitter bot
Python Twitter Bot Installation
You can install the Twitter Follow Bot utilizing pip:
1 | pip install TwitterFollowBot |
Conditions
You should install’s python-twitter library:
1 | pip install twitter |
In spite of the fact that this library ought to be installed alongside the Twitter Follow Bot in the event that you utilized pip.
You will likewise need to make an application account on https://dev.twitter.com/applications
- Sign in with your Twitter account
- Make another application account
- Adjust the settings for that application record to permit read and compose
- Produce another OAuth token with those authorizations
- Following these means will make 4 tokens that you should put in the design record talked about underneath.
Python Twitter Bot Utilization
Designing the Twitter bot
Before running the bot, you should first set it up so it can associate with the Twitter API. Make a config.txt document and fill in the following data:
1 2 3 4 5 6 7 8 9 10 11 12 13 | OAUTH_TOKEN: OAUTH_SECRET: CONSUMER_KEY: CONSUMER_SECRET: TWITTER_HANDLE: ALREADY_FOLLOWED_FILE:already-followed.txt FOLLOWERS_FILE:followers.txt FOLLOWS_FILE:following.txt USERS_KEEP_FOLLOWING: USERS_KEEP_UNMUTED: USERS_KEEP_MUTED: FOLLOW_BACKOFF_MIN_SECONDS:10 FOLLOW_BACKOFF_MAX_SECONDS:60 |
OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET are your API keys that you got from making your application account. TWITTER_HANDLE is your Twitter name, case-touchy.
You can change the FILE sections on the off chance that you need to store that data in a particular area on your PC. Naturally, the documents will be made in your present catalog.
Include comma-isolated Twitter client IDs to the USERS_KEEP passages to:
- USERS_KEEP_FOLLOWING: Keep following these clients regardless of whether they don’t follow you back.
- USERS_KEEP_UNMUTED: Keep these clients unmuted (i.e., you get a versatile warning when they tweet)
- USERS_KEEP_MUTED: Keep these clients quieted (i.e., you don’t get a versatile warning when they tweet)
Example:
1 2 3 | FOLLOWS_FILE:following.txt USERS_KEEP_FOLLOWING:1234,1235,1236 USERS_KEEP_UNMUTED: |
You can look into a clients’ Twitter ID here.
Make an example of the bot
To make an example of the bot:
1 2 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() |
Of course, the bot will search for an arrangement document called config.txt in your momentum catalog.
On the off chance that you need to utilize an alternate arrangement document, pass the setup record to the bot as follows:
1 2 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot("my-other-bot-config.txt") |
Note this enables you to run numerous occasions of the bot with various designs, for instance on the off chance that you run different Twitter accounts:
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_other_bot = TwitterBot("my-other-bot-config.txt") |
Adjusting your Twitter following locally
Because of Twitter API rate restricting, the bot must keep up a nearby reserve of the majority of your followers so it doesn’t utilize the greater part of your API time looking into your followers. It is profoundly prescribed to adjust the bot’s nearby store day by day:
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.sync_follows() |
The bot will make store records where you determined in the design document.
Try not to erase the store records (“followers.txt”, “follows.txt”, and “right now followed.txt” as a matter of course) except if you need to begin the bot once again with a new reserve.
Robotizing Twitter activities with the bot
This bot has a few capacities for automatically interfacing with Twitter:
Auto follow any clients that tweet something with a particular expression
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_follow("phrase") |
You can likewise look in view of hashtags:
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_follow("#hashtag") |
Like default, the bot looks into the 100 latest tweets. You can change this number with the tally parameter:
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_follow("phrase", count=1000) |
Auto follow any users that have followed you
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_follow_followers() |
Auto follow any users that follow a user
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_follow_followers_of_user("jack", count=1000) |
Auto most loved any tweets that have a particular expression
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_fav("phrase", count=1000) |
Auto retweet any tweets that have a particular expression
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_rt("phrase", count=1000) |
Auto unfollow any clients that have not followed you back
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_unfollow_nonfollowers() |
On the off chance that there are sure clients that you might want to not unfollow, add their client id to the USERS_KEEP_FOLLOWING list.
You should physically alter the code on the off chance that you need to include uncommon clients that you will continue following regardless of whether they don’t follow you back.
Auto unfollow all users
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_unfollow_all_followers() |
Auto quiet all clients that you have followed
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_mute_following() |
You should physically alter the code on the off chance that you need to include uncommon clients that you won’t quiet.
Auto unmute everybody you have quieted
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_unmute() |
You should physically alter the code in the event that you need to include exceptional clients that will stay quieted.
Post a tweet on twitter
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.send_tweet("Hello world!") |
Auto add users tweeting about brief comment of your list
1 2 3 | from TwitterFollowBot import TwitterBot my_bot = TwitterBot() my_bot.auto_add_to_list("#TwitterBot", "twitterbot-list", count=10) |
In the case over, the bot will attempt to add 10 clients to the twitterbot-list that are tweeting #TwitterBot.
Keep in mind that the maximum number of clients in a list is 5000.
Project Files;