Created
April 28, 2014 02:30
-
-
Save jamesnvc/11360477 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python2.7 | |
"""To use: | |
First, run `pip install python-twitter` | |
Then, you'll need to create a twitter application at apps.twitter.com. This | |
will give you the API key & secret. Set its permissions to be Read & Write. | |
Then you'll generate an access token on the same page and put all four values | |
in the appropriate variables below. | |
Once that's done, just run ./twitter_autoblock_rts.py <some-tweet-id> | |
Optionally give the --silent flag to block everyone without prompts | |
""" | |
import twitter | |
import argparse | |
parser = argparse.ArgumentParser(description="Block all users that retweeted a given tweet") | |
parser.add_argument('tweet_id', metavar='tweet-id', type=int, help='tweet id') | |
parser.add_argument('--silent', dest='silent', action='store_const', | |
const=True, default=False, | |
help="Don't ask for each user, just block 'em all") | |
args = parser.parse_args() | |
tweet_id = args.tweet_id | |
print "Getting retweeters of {}".format(tweet_id) | |
API_KEY = "" | |
API_SECRET = "" | |
ACCESS_TOKEN = "" | |
ACCESS_TOKEN_SECRET = "" | |
api = twitter.Api(consumer_key=API_KEY, | |
consumer_secret=API_SECRET, | |
access_token_key=ACCESS_TOKEN, | |
access_token_secret=ACCESS_TOKEN_SECRET) | |
def block_user(user): | |
url = '%s/blocks/create.json' % api.base_url | |
resp = api._RequestUrl(url, 'POST', {'screen_name': user.screen_name, | |
'skip_status': 1}) | |
print resp | |
print "Blocked {}".format(user.screen_name) | |
for retweeter in api.GetRetweeters(tweet_id): | |
user = api.GetUser(retweeter) | |
if args.silent: | |
block_user(user) | |
else: | |
confirm = raw_input("Block {}? [Y/n]".format(user.screen_name)) | |
if confirm != 'n': | |
block_user(user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on Shanley's request, automatically block anyone RT'ing a given tweet.
Blocking ★'ers to come