• Stars
    star
    1,309
  • Rank 35,952 (Top 0.8 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python bot that automates several actions on Twitter, such as following users and favoriting tweets.

PyPI version Python 2.7 Python 3.5 License

Twitter Bot

Join the chat at https://gitter.im/rhiever/TwitterFollowBot

A Python bot that automates several actions on Twitter, such as following users and favoriting tweets.

Notice: Repository is no longer being maintained

Twitter has started cracking down heavily on users who use bots like this one to follow users or favorite tweets en masse. For that reason, I am no longer developing this code repository but will leave it up for anyone who wants to use it as a code base for future projects. Please respect the software license if you use the code from this repository.

Disclaimer

I hold no liability for what you do with this bot or what happens to you by using this bot. Abusing this bot can get you banned from Twitter, so make sure to read up on proper usage of the Twitter API.

Installation

You can install the Twitter Follow Bot using pip:

pip install TwitterFollowBot

Dependencies

You will need to install Python's python-twitter library:

pip install twitter

Although this library should be installed along with the Twitter Follow Bot if you used pip.

You will also need to create an app account on https://dev.twitter.com/apps

  1. Sign in with your Twitter account
  2. Create a new app account
  3. Modify the settings for that app account to allow read & write
  4. Generate a new OAuth token with those permissions

Following these steps will create 4 tokens that you will need to place in the configuration file discussed below.

Usage

Configuring the bot

Before running the bot, you must first set it up so it can connect to the Twitter API. Create a config.txt file and fill in the following information:

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 received from creating your app account. TWITTER_HANDLE is your Twitter name, case-sensitive.

You can change the FILE entries if you want to store that information in a specific location on your computer. By default, the files will be created in your current directory.

Add comma-separated Twitter user IDs to the USERS_KEEP entries to:

  • USERS_KEEP_FOLLOWING: Keep following these users even if they don't follow you back.

  • USERS_KEEP_UNMUTED: Keep these users unmuted (i.e., you receive a mobile notification when they tweet)

  • USERS_KEEP_MUTED: Keep these users muted (i.e., you don't receive a mobile notification when they tweet)

For example:

...
FOLLOWS_FILE:following.txt
USERS_KEEP_FOLLOWING:1234,1235,1236
USERS_KEEP_UNMUTED:
...

You can look up a users' Twitter ID here.

Create an instance of the bot

To create an instance of the bot:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()

By default, the bot will look for a configuration file called config.txt in your current directory.

If you want to use a different configuration file, pass the configuration file to the bot as follows:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot("my-other-bot-config.txt")

Note that this allows you to run multiple instances of the bot with different configurations, for example if you run multiple Twitter accounts:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_other_bot = TwitterBot("my-other-bot-config.txt")

Syncing your Twitter following locally

Due to Twitter API rate limiting, the bot must maintain a local cache of all of your followers so it doesn't use all of your API time looking up your followers. It is highly recommended to sync the bot's local cache daily:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.sync_follows()

The bot will create cache files where you specified in the configuration file.

DO NOT delete the cache files ("followers.txt", "follows.txt", and "already-followed.txt" by default) unless you want to start the bot over with a fresh cache.

Automating Twitter actions with the bot

This bot has several functions for programmatically interacting with Twitter:

Automatically follow any users that tweet something with a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("phrase")

You can also search based on hashtags:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("#hashtag")

By default, the bot looks up the 100 most recent tweets. You can change this number with the count parameter:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("phrase", count=1000)

Automatically follow any users that have followed you

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow_followers()

Automatically follow any users that follow a user

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot() 
my_bot.auto_follow_followers_of_user("jack", count=1000)

Automatically favorite any tweets that have a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_fav("phrase", count=1000)

Automatically retweet any tweets that have a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_rt("phrase", count=1000)

Automatically unfollow any users that have not followed you back

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unfollow_nonfollowers()

If there are certain users that you would like to not unfollow, add their user id to the USERS_KEEP_FOLLOWING list.

You will need to manually edit the code if you want to add special users that you will keep following even if they don't follow you back.

Automatically unfollow all users.

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unfollow_all_followers()

Automatically mute all users that you have followed

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_mute_following()

You will need to manually edit the code if you want to add special users that you will not mute.

Automatically unmute everyone you have muted

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unmute()

You will need to manually edit the code if you want to add special users that will remain muted.

Post a tweet on twitter

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.send_tweet("Hello world!")

Automatically add users tweeting about something to one of your list

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_add_to_list("#TwitterBot", "twitterbot-list", count=10)

In the example above, the bot will try to add 10 users to the twitterbot-list that are tweeting #TwitterBot.

Remember that the max number of users in a list is 5000.

Have questions? Need help with the bot?

If you're having issues with or have questions about the bot, file an issue in this repository so one of the project managers can get back to you. Please check the existing (and closed) issues to make sure your issue hasn't already been addressed.

More Repositories

1

Data-Analysis-and-Machine-Learning-Projects

Repository of teaching materials, code, and data for my data analysis and machine learning projects.
Jupyter Notebook
6,107
star
2

datacleaner

A Python tool that automatically cleans data sets and readies them for analysis.
Python
1,054
star
3

reddit-analysis

A Python script that parses post titles, self-texts, and comments on reddit and makes word clouds out of the word frequencies.
Python
285
star
4

optimal-roadtrip-usa

Contains maps for the article, "Computing the optimal road trip across the U.S." and similar articles
HTML
230
star
5

sklearn-benchmarks

A centralized repository to report scikit-learn model performance across a variety of parameter settings and data sets.
Jupyter Notebook
210
star
6

python-data-visualization-course

Course materials for teaching data visualization in Python.
Jupyter Notebook
169
star
7

reddit-twitter-bot

Looks up posts from reddit and automatically posts them on Twitter.
Python
137
star
8

name-age-calculator

Analyzes a name and guesses the age range of a person with that name.
HTML
43
star
9

redditviz

An interactive map of reddit: the "front page of the internet"
CSS
38
star
10

MarkovNetwork

Python implementation of Markov Networks for neural computing.
Python
36
star
11

ipython-notebook-workshop

Beginner's IPython Notebook Tutorial
19
star
12

baby-name-explorer

HTML
17
star
13

network-analysis-scripts

A bunch of useful scripts for analyzing networks.
Python
13
star
14

active-categorical-classifier

A tool that evolves small brains capable of scanning and classifying an image.
Jupyter Notebook
12
star
15

k-fold-cv-benchmark

Python
9
star
16

optimized-us-capitol-road-trip

HTML
9
star
17

crowd-machines

Jupyter Notebook
8
star
18

xrff2csv

A Python tool that converts XRFF files to CSV format.
Python
7
star
19

edd

A tool that evolves small brains capable of scanning and classifying an image.
C++
7
star
20

rhiever.github.io

Dr. Randal Olson's personal website
HTML
5
star
21

Collective-Cognition-Increases-Accuracy

Code for the model in the paper, "Accurate decisions in an uncertain world: collective cognition increases true positives while decreasing false positives."
Python
5
star
22

rhiever-bot

Bot that monitors /r/MUWs and runs the MUW script.
Python
4
star
23

big-ten-twitter-network

Interactive visualization of the Big Ten football teams on Twitter
JavaScript
3
star
24

biped-hyperneat

ODE implementation of a walking biped robot with HyperNEAT evolving the neural controller
PHP
3
star
25

dissertation-topic-network

Dissertation topic network
3
star
26

big-data-hw

2
star
27

Intro-to-Evolutionary-Modeling

Material for teaching biologists to work with digital evolutionary models.
2
star
28

rmagic-tutorial

A brief tutorial showing how Rmagic can be used in IPython Notebook.
2
star
29

marriage-divorce-stats

144 years of marriage and divorce in 1 chart
HTML
1
star
30

EvoRoboCodeGECCO2013

Description of our EvoRoboCode competition submission to GECCO 2013.
1
star
31

drug-alcohol-mentions

1
star
32

2014-01-30-mit

Software Carpentry bootcamp at Massachusetts Institute of Technology on January 30-31, 2014
Python
1
star
33

betting-game

Game Theory: betting game
C++
1
star
34

temp-repo

HTML
1
star
35

eos-old

Evolution of Swarming Platform
C++
1
star
36

ipython-example

Example notebook showing how to do statistics in IPython Notebook.
Python
1
star
37

AMT-biped-analysis

1
star
38

eos-active-perception

EOS with agents who have to actively perceive the environment with a fine-grained retina.
C++
1
star