Created
August 20, 2008 08:15
-
-
Save mikeyk/6341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "Only follow you:" | |
for member in follow_list.difference(friend_list): | |
print member | |
print "Only you follow:" | |
for member in friend_list.difference(follow_list): | |
print member | |
print "Stats" | |
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