Python Twitter Bot
Necessary program modules and
- Python 3.5.0
- Tweepy Module
- Time module
# I’m using pycharm so I’ll tell you about pycharm
You can download the Modul you want from there by entering the project settings in the Settings section
What we need is how to put your Twitter account into this program, first of all, api.twitter.com login to the site to add programs there are consumer keyular access tokens located in the code
Write your keys to this region
Warning: you cannot receive keys unless you have added a phone number.
This program follows the followers in someone else’s account.
View Bot
1 2 3 4 | self.CONSUMER_KEY = 'write' self.CONSUMER_KEY_SECRET = 'here' self.ACCESS_TOKEN = ':D' self.ACCESS_TOKEN_SECRET = '' |
This program follows the followings in someone else’s account.
1 2 | twitter_bot.grab_users_followers("here") twitter_bot.mass_follow(twitter_bot.user_list) |
type in here without the ‘@’ sign, if you want to keep track of who is at the end of the code.
It is a very simple program that will follow you as you work automatically.
http://www.tweepy.org
https://www.python.org/downloads/release/python-350/
Twitter Bot Codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import tweepy import time class Bot: def __init__(self): self.CONSUMER_KEY = '' self.CONSUMER_KEY_SECRET = '' self.ACCESS_TOKEN = '' self.ACCESS_TOKEN_SECRET = '' self.api = self.authenticate() self.user_list = [] def authenticate(self): auth = tweepy.OAuthHandler(self.CONSUMER_KEY, self.CONSUMER_KEY_SECRET) auth.set_access_token(self.ACCESS_TOKEN, self.ACCESS_TOKEN_SECRET) api = tweepy.API(auth) try: api.verify_credentials() except: print("The bot was unable to authenticate") else: print("The bot has been authenticate") return api def grab_users_followers(self, user): for page in tweepy.Cursor(self.api.followers_ids, user).pages(): self.user_list.extend(page) time.sleep(5) print(len(self.user_list), "users in list") def mass_follow(self, users): for user in users: self.api.create_friendship(user) print("You are following iser ID: {}".format(user)) time.sleep(1) twitter_bot = Bot() twitter_bot.grab_users_followers("") twitter_bot.mass_follow(twitter_bot.user_list) |