Skip to content

Instantly share code, notes, and snippets.

@j4mie
Created June 17, 2009 20:37
Show Gist options
  • Save j4mie/131489 to your computer and use it in GitHub Desktop.
Save j4mie/131489 to your computer and use it in GitHub Desktop.
Twitter Heathens: Find people you follow who don't follow you back
# By twitter.com/j4mie
#
# Like this: http://blog.davidziegler.net/post/107429458/see-which-twitterers-don-t-follow-you-back-in-less-than
# ..but with API pagination (in case you have more than 100 friends or followers).
# Needs this: http://code.google.com/p/python-twitter/
# ..which needs this: http://cheeseshop.python.org/pypi/simplejson
import twitter, getpass, sys
def page_function(function):
page = 1
all_results = []
while(True):
results_for_page = function(page=page)
if len(results_for_page) == 0:
break
all_results.extend(results_for_page)
page = page + 1
return all_results
def get_heathens(username, password):
print 'Finding heathens...'
api = twitter.Api(username, password)
friends = set([friend.screen_name for friend in page_function(api.GetFriends)])
followers = set([follower.screen_name for follower in page_function(api.GetFollowers)])
heathens = friends - followers
print "There are %i people you follow who do not follow you:" % len(heathens)
heathens = list(heathens)
heathens.sort(key=lambda x: str(x).lower())
for heathen in heathens:
print heathen
if __name__ == "__main__":
try:
get_heathens(sys.argv[1], getpass.getpass())
except Exception, error:
print 'Something went wrong:', error.message
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment