Skip to content

Instantly share code, notes, and snippets.

@shashi
Created November 21, 2009 08:23
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 shashi/240058 to your computer and use it in GitHub Desktop.
Save shashi/240058 to your computer and use it in GitHub Desktop.
# Python Script to block spammy subscribers from your identi.ca account.
# bug me: identi.ca/g0
import json
import sys
import urllib2
apipath = 'http://identi.ca/api'
username = raw_input('Your username: ')
password = raw_input('Your password: ')
print "Getting a list of subscribers..."
### Basic HTTP authentication taken from ur1.ca/govf
# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password.
# If we knew the realm, we could use it instead of ``None``.
password_mgr.add_password(None, apipath, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib2.build_opener(handler)
# use the opener to fetch a URL
followers = json.loads(opener.open(apipath + '/statuses/followers.json').read())
# Install the opener.
# Now all calls to urllib2.urlopen use our opener.
urllib2.install_opener(opener)
###
print """Done fetching followers. Now type <option><enter> for the name prompted.
Options:
y -> block
f -> force unsubscribe (block, then unblock)
n -> don't block
q -> quit script"""
for follower in followers:
i = follower['id']
name = follower['name']
b = raw_input(name+'? (y/f/n/q) ')
if(b.strip() == 'y' or b.strip() == 'f'):
if(urllib2.urlopen(apipath + '/blocks/create/'+str(i)+'.json', '')):
if(b.strip() == 'f'):
if(urllib2.urlopen(apipath + '/blocks/destroy/'+str(i)+'.json', '')):
print "force unsubscribed "+follower['name']+'.'
else:
print "blocked "+follower['name']+'.'
if(b.strip() =='q'):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment