Skip to content

Instantly share code, notes, and snippets.

@affix
Created November 25, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save affix/4143831 to your computer and use it in GitHub Desktop.
Save affix/4143831 to your computer and use it in GitHub Desktop.
Auto Block Twitter mentions who you do not follow
#!/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