Skip to content

Instantly share code, notes, and snippets.

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 mikeyk/6341 to your computer and use it in GitHub Desktop.
Save mikeyk/6341 to your computer and use it in GitHub Desktop.
from BeautifulSoup import BeautifulSoup
def main():
friendsfl = open('friends.xml')
followersfl = open('followers.xml')
friendsoup = BeautifulSoup(friendsfl)
followsoup = BeautifulSoup(followersfl)
friend_list = set()
follow_list = set()
for friend in friendsoup('user'):
friend_list.add(friend.contents[3].next)
for follower in followsoup('user'):
follow_list.add(follower.contents[3].next)
print "Common:"
for member in follow_list.intersection(friend_list):
print member
print
print "Only follow you:"
for member in follow_list.difference(friend_list):
print member
print
print "Only you follow:"
for member in friend_list.difference(follow_list):
print member
print
print "Stats"
print
print "You follow, and follow you back:"
print "%.2f" % (len(friend_list.intersection(follow_list)) / float(len(friend_list))*100),'%'
print "Follow you, but you don't follow back:"
print "%.2f" % ((1-len(follow_list.intersection(friend_list)) / float(len(follow_list)))*100),'%'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment