Skip to main content

Python script to identify and block your bot followers on Twitter

Project description

Python program to identify and block your bot followers on Twitter

Requires 3.4 <= Python <= 3.7

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Installing

Only if you use Python >= 3.7, you have to run this command first:

sudo pip install https://github.com/tweepy/tweepy/archive/master.zip

Now, no matter what Python version you’re using (if it fits the requirement), the easiest way is installing using pip:

sudo pip install botblocker

You can also clone this project using git:

git clone https://github.com/yanorestes/botblocker.git
cd botblocker
python setup.py install

Preparation

At first, setting things up to botblocker may sound overcomplicated. However, following this step-by-step tutorial will ensure an easy proceedment! Still, this “hard” part of the tutorial will have to be followed only once ;)!

1 - Getting your Twitter Developer Account

As I’m providing the complete code of this project, I can’t let you guys use my API keys, so you need to get them yourselves. This is how you do it:

  • Access this link to associate your Twitter profile with a developer account

  • Click in Continue

  • Check “I am requesting access for my own personal use”

  • Type in your username on the field below

  • Select the country you live and press Continue

  • Check “Consumer / end-user experience”

  • In the textbox below, type something similar to the following example (note that it is better not to copy the whole text, so that your application will be approved faster):

The project I'm building aims to identify and block follower bots. It is based on programming language Python, using Tweepy to connect to Twitter API and Botometer to identify bots. The project gives the user mutiple options on identifying and blocking the bots, resulting in a clean and simple usage. Botometer analizes each profile basing itself on the tweets and the specs of the profile, to, then, calculate a result (a score from 0 to 5; the higher, the more likely it is that the profile is indeed a bot). None of the results are shared with anyone or kept with us.
  • Check No and click Continue

  • Scroll through the terms of service and check the “read and agree” box

  • Click on “Submit application”

  • Check your email account and confirm your email

  • Wait for your Developer Account to get approved

2 - Getting your Twitter API Keys

Once your Developer Account gets approved, you can pass on to creating an app:

  • Access this link to register your app

  • Chose an authentic name to your app and fill the first field

  • In the textbox below, type something similar to the following example:

Python program to identify and block your bot followers on Twitter.
The project I'm building aims to identify and block follower bots. It is based on programming language Python, using Tweepy to connect to Twitter API and Botometer to identify bots. The project gives the user mutiple options on identifying and blocking the bots, resulting in a clean and simple usage.
  • Click on Create and confirm

You will be redirected to your app’s page. Then:

  • Access the “Keys and tokens” tab

  • Save the two keys under “Consumer API keys” somewhere. The first is your Consumer Key and the second is your Consumer Secret Key. You will need both of them later configuring botblocker:

https://cdn.pbrd.co/images/HEvDXKu.png

3 - Getting your Mashape API Key

With your Twitter API keys in hands, you’ll only have to get your Mashape API Key. Follow these steps in order to do so:

  • Access this link and register an account (I recommend signing up with GitHub, but there are other options)

  • If you have a credit card available (you won’t have to pay a single dollar, don’t worry!), access this link, click on Pricing and subscribe to the Basic Free Plan. If you don’t, you can use this link. The first link will (probably) make the program run faster.

  • On this link, copy your personal “X-Mashape-Key” on the request example code and save somewhere:

https://my.mixtape.moe/nqkagq.png

Using

Now it’s time to finally run botblocker! Botblocker you’ll go through all of your followers and calculate a “bot score” of them. The score goes from 0 to 5. The higher the score, the more likely is the chance the profile is a bot. The default behaviour is to automatically block every profile identified as a bot.

If you installed the package using pip, you can simply run botblocker in the command line:

botblocker [-h] [-c] [--noblock] [--saveallowlist] [--softblock] [--report] [-l {1,2,3}] -u USER [-v]

These are the parameters you can use:

  • -h or --help - Shows a help message and exit

  • -c or --config - (Re)configure usage settings. At least once, you’ll have to do this.

  • --noblock - Don’t block anyone automatically. This is not recommended, especially for profiles with lots of followers, as you may lose all the running progress if you exit early.

  • --saveallowlist - Save users identified as non-bots to an allowlist. Recommended.

  • --softblock - Do soft block (block and unblock right after)

  • -r or --report - Report users identified as bots to Twitter

  • -l {1,2,3} or -level {1,2,3} - Choose level of rigorosity to use to identify bots. Level 1 only consider bots those with score >= 4, level 2 (default) considere those with score >= 3 and level 3 considere those with score >= 2.5.

  • -u USER or -user USER - The Twitter username you want to run botblocker for. Required.

  • -v or --version - Get the current version of botblocker

You can also run the script directly by botblocker.py:

python -W ignore -m botblocker [-h] [-c] [--noblock] [--saveallowlist] [--softblock] [--report] [-l {1,2,3}] -u USER [-v]

Contributing

I’m accepting pull requests that improve speed and legibility of the code.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

botblocker-1.1.3.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file botblocker-1.1.3.tar.gz.

File metadata

  • Download URL: botblocker-1.1.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for botblocker-1.1.3.tar.gz
Algorithm Hash digest
SHA256 26ccb485e356a8ff84c39419ee42a9e7e2dfcfb9b8a63a9cc09752b823f38ef6
MD5 de48dbd8efe666d4c9dc8fd62a028230
BLAKE2b-256 d0f86e6c9baa5f2c3a62d8e16bfb5c81bd27acc130ab3eac2a84ddf452221fb9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page