Skip to content

Instantly share code, notes, and snippets.

@danfishgold
Created October 15, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danfishgold/5e39d65c03e9aa5a379e to your computer and use it in GitHub Desktop.
Save danfishgold/5e39d65c03e9aa5a379e to your computer and use it in GitHub Desktop.
Use this to block fake followers. You need to find an account that the fake users are all following
'''
This is a python script to block those extra fake followers.
Here's what you have to do:
# Twitter Authorization
1. Go to apps.twitter.com
2. Click on Create New App
3. Fill in the stuff. None of it matters
4. Go to Keys and Access Tokens
5. Click on Create my access token
6. Copy the consumer key, consumer secret, access token, and access token secret
7. Paste them in the script (those first lines after the `import`s)
# Detective work stuff (not really)
Go over the followers you have that look fake.
They probably follow other accounts that bought followers.
If the script finishes and there are still a lot of fake followers, you should
check who they follow for a repeating followee(?) and add it to the list
named `suspicious_account_screen_names` in the script.
# Python stuff
1. Open Terminal.app
2. Enter `pip install tweepy` and give it a few seconds
3. If it produces an error (a bunch of red text) use `sudo pip install tweepy`
4. Enter `python ` (don't forget the space!) (and don't hit return yet)
5. Drag this file to the Terminal window. Its path should be filled in
6. Hit return
It will take a while...
Every account that follows these suspicious accounts will be blocked by the user
who issued the API tokens. You can then export the list of blocked accounts
(on twitter.com) and give it to someone else to import.
# Notes
If you have any problems you can tweet @tennabey (or DM me).
And if it's because of an error you should probably take a screenshot of the
Terminal window.
If you want to stop the script just hit Ctrl+C
'''
import tweepy
import re
from time import time, sleep
from datetime import datetime
auth = tweepy.OAuthHandler('CONSUMERKEY',
'CONSUMERSECRET')
auth.set_access_token('ACCESSTOKEN',
'ACCESSTOKENSECRET')
username = 'USERNAME'
suspicious_account_screen_names = ['add', 'accounts' 'that fake followers also follow', 'here', '(without @ symbols.)']
api = tweepy.API(auth)
number_of_blocked = 0
friendship_limit = api.rate_limit_status()['resources']['friendships']['/friendships/show']
number_of_friendship_requests = friendship_limit['limit'] - friendship_limit['remaining']
for i, follower in enumerate(tweepy.Cursor(api.followers, screen_name=username).items()):
print 'follower #{}: {}'.format(i+1, follower.screen_name)
for suspicious_account in suspicious_account_screen_names:
if number_of_friendship_requests >= 175: # rate limit is 180 per 15 minutes
reset = api.rate_limit_status()['resources']['friendships']['/friendships/show']['reset']
continue_time = datetime.fromtimestamp(reset).strftime('%H:%M:%S')
print 'waiting for rate limit... (will continue at {})'.format(continue_time)
sleep(reset - time() + 1)
number_of_friendship_requests = 0
friendship = api.show_friendship(source_screen_name=suspicious_account,
target_screen_name=follower.screen_name)
number_of_friendship_requests += 1
if friendship[0].followed_by:
number_of_blocked += 1
print 'blocked ({} already)'.format(number_of_blocked)
api.create_block(screen_name=follower.screen_name)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment