twitter: who follows who?
April 13, 2009
#!/usr/bin/env python
import sys, urllib2, twitter
def main(*args):
try:
t = twitter.Api('A_VALID_USER', 'A_VALID_PASSWORD')
f = t.GetFriends(user=args[1])
if any(u for u in f if u.screen_name == args[2]):
print 'yup, %s follows %s' % (args[1], args[2])
else:
print 'nup, %s does not follow %s' % (args[1], args[2])
except urllib2.HTTPError, e:
if e.code == 404:
print "soz, %s isn't a user" % (args[1])
else:
raise e
if __name__ == '__main__':
if len(sys.argv) > 1:
main(*sys.argv)
else:
print "who follows who?"
A hackity hack to find out if one twittard is following another.
You’ll need python-twtitter and simplejson, just do:
> python twit.py twittard1 twittard2
or stick it in ~/bin and chmod +x it, a la caolan’s suggestion