Forked from danfishgold/block_fake_followers.py
Last active
January 25, 2016 03:44
-
-
Save celesteh/b75eca9bd20da4245cfe to your computer and use it in GitHub Desktop.
Use this to block all followers of someone encouraging harassment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This is a python script to block all followers of a particular user. | |
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) | |
Get the user accounts of people you want to block all followers of | |
# 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 you want to block followers of', '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 suspicious_account in suspicious_account_screen_names: | |
for i, follower in enumerate(tweepy.Cursor(api.followers, screen_name=suspicious_account).items()): | |
print 'follower #{}: {}'.format(i+1, follower.screen_name) | |
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=follower.screen_name, | |
target_screen_name=username) | |
if friendship[0].followed_by: | |
print '------Spared!' | |
else: | |
number_of_blocked += 1 | |
#print 'blocked ({} already)'.format(number_of_blocked) | |
api.create_block(screen_name=follower.screen_name) | |
number_of_friendship_requests += 1 | |
print 'blocked {} accounts'.format(number_of_blocked) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment