insomnihack

When sleep eludes, the keyboard beckons

Tracking followers with python-twitter

December 25, 2009 Dale 1 Comment

There are a lot of applications out there to help manage your twitter account. Much of what these applications have to offer can be achieved with very little python code. For example, say you want to find out who is following you that you’re not following. Alternately, say you want to find out who you’re following, but who isn’t following you in return. You can find this information out easily with python-twitter and a few lines of code.

[python]
#!/usr/bin/env python

import twitter

if __name__ == ‘__main__’:
api = twitter.Api(username=’username’, password=’password’)
i_follow = api.GetFriends()
follow_me = api.GetFollowers()
i = [u.name for u in i_follow]
f = [u.name for u in follow_me]
i_should_follow = [n for n in f if n not in i]
i_should_drop = [n for n in i if n not in f]

print ‘I follow:’
print ‘\n’.join(i)
print
print ‘Following me:’
print ‘\n’.join(f)
print
print ‘I should consider following:’
print ‘\n’.join(i_should_follow)
print
print ‘I should consider not following:’
print ‘\n’.join(i_should_drop)
print
[/python]

Replace the dummy user name and password and give it a go.

Programming Python, twitter

Comments

  1. Waldo says

    July 8, 2010 at 11:33 AM

    Dont think the code gets all the followers and following
    because twitter limits the number to about 100 or so.

    Great concise code though 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

About Me

Hi, my name's Dale, and this is my tech blog. Read More…

Search

Tags

blogging c# database Django documentation Email furniture git hacks htpc IPython Linux mac nas packaging PyCharm Python Roleplaying tools twitter unit tests virtualenv Visual Studio vmware Windows

Copyright © 2025 · Equilibre Theme on Genesis Framework · WordPress · Log in