-
-
Save grcninja/699ce68c6ab59d73b88b 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 | |
#Python3.4.3 compatable | |
#All the credit for this goes to the original author 00101010b. | |
#I just added a for loop and list of possible account names. | |
# 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'}))) | |
#list of possible varioations on account names | |
iph_derp = ("iPh0ne6","iph0ne6","iPhon36","iphon36","iPh0ne 6","iph0ne 6","iPhon3 6","iphon3 6","iPh0ne Six","iph0ne Six","iPhon3 Six","iphon3 Six") | |
for i in range(len(iph_derp)): | |
# 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': str(i), '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) |
Limits? How many users can be blocked with it ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm a noob at programming. How can I use this script to use my CSV file of user account names I want to block? It is a csv file with 30k troll accounts. Please help.