Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created September 21, 2010 14:14
Show Gist options
  • Save neilkod/589734 to your computer and use it in GitHub Desktop.
Save neilkod/589734 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import tweepy
def intersect(a, b):
return list(set(a) & set(b))
CONSUMER_KEY = 'xxx'
CONSUMER_SECRET = 'yyy'
ACCESS_KEY = 'zzzz'
ACCESS_SECRET = '2222'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
userA="morewillie"
userAfriends = []
userAfollowers = []
userB="joelkodner"
userBfriends = []
userBfollowers = []
for friend in tweepy.Cursor(api.friends, id=userA).items():
userAfriends.append(friend.screen_name)
for friend in tweepy.Cursor(api.followers,id=userA).items():
userAfollowers.append(friend.screen_name)
print "%s has %d friends and %d followers" % (userA,len(userAfriends),len(userAfollowers))
#print myfollowers
#print len(myfollowers)
userBfriends=[]
for friend in tweepy.Cursor(api.friends, id=userB).items():
userBfriends.append(friend.screen_name)
userBfollowers = []
for follower in tweepy.Cursor(api.followers, id=userB).items():
userBfollowers.append(follower.screen_name)
print "%s has %d friends and %d followers" % (userB,len(userBfriends),len(userBfollowers))
print " "
print "--------"
print " "
intFriends= intersect(userAfriends,userBfriends)
print "%s and %s have %d friends in common:" % (userA,userB,len(intFriends))
print intFriends
print " "
print "--------"
print " "
intFollowers= intersect(userAfollowers,userBfollowers)
print "%s and %s have %d followers in common:" % (userA,userB,len(intFollowers))
print intFollowers
print " "
print "--------"
print " "
intFriendsAndFollowers=intersect(intFriends,intFollowers)
print "%s and %s have %d friends and followers in common:" % (userA,userB,len(intFriendsAndFollowers))
print intFriendsAndFollowers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment