Last active
November 11, 2015 01:54
-
-
Save 00101010b/0f47c4bd353b7133b846 to your computer and use it in GitHub Desktop.
Simple script to block annoying twitter spammers. Requires twitter API codes.
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
#!/usr/bin/env python | |
# Import TwitterAPI | |
# you can install this library via the commandline: | |
# $ pip install --user TwitterAPI | |
from TwitterAPI import TwitterAPI | |
# setup TwitterAPI | |
# you will have to get an API key set from: https://apps.twitter.com/ before you can use this script. | |
api = TwitterAPI( \ | |
consumer_key='redacted', \ | |
consumer_secret='redacted', \ | |
access_token_key='redacted', \ | |
access_token_secret='redacted' \ | |
) | |
# get a list of already blocked users. | |
blockedUsers = list(set(user['screen_name'] for user in api.request('blocks/list', {'include_entities': 'false', 'skip_status':'true'}))) | |
# perform our search for iphone spam and get the list of users. | |
for user in list(set(post['user']['screen_name'] for post in api.request('search/tweets', {'q': 'iPh0ne 6 AND bi0', 'count':'100', 'include_entities':'false'}))): | |
# check if our current user is already in our block list | |
# if they are let us know about it. | |
if user in blockedUsers: | |
print "User '%s' already blocked." % user | |
continue | |
# if they aren't, block them. | |
else: | |
blocked = api.request('blocks/create', {'screen_name': user}) | |
if blocked: | |
print "Blocked user: [ @%s ]." % user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will need to get an Twitter API key from https://apps.twitter.com/ before using this script. Make sure you review any blocked twitter accounts on twitter after this script has been run, this is so you don't block the wrong people.