Created
November 25, 2012 14:56
-
-
Save affix/4143831 to your computer and use it in GitHub Desktop.
Auto Block Twitter mentions who you do not follow
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 | |
# autoblock-twitter.py | |
# Automatically block twitter users who mention you in a tweet that you do not follow. | |
# I wrote this as my user is @cli and I was constantly getting unrelated spam mentions | |
# License : GPLv2+ | |
# Author : Keiran "Affix" Smith <Affix_AT_affix_DOT_me> | |
import tweepy | |
consumer_key="" | |
consumer_secret="" | |
access_token="" | |
access_token_secret="" | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
count = 0 | |
mentions = tweepy.Cursor(api.mentions).items() | |
for status in mentions: | |
if status.user.following or status.user.verified: | |
print "Not Blocking : " + status.user.screen_name + " %r" % status.user.verified | |
else: | |
api.create_block(status.user.screen_name) | |
api.update_status("Blocked User : @" + status.user.screen_name) | |
count = count + 1 | |
api.update_status("@twitter Auto Block blocked : %d users" % count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment