import measures import tweetutils def print_welcome(message = "Welcome to 'DISSS"): print "*"*79 print "%s%s%s" % (" "*((80 - len(message))/2), message, " "*((80 - len(message))/2)) print "*"*79 print_welcome() while True: your_username = raw_input("Enter your Twitter username: "******"Enter someone else's: ") if your_username == ''and another_username == '': print "Bye!" break your_friends = tweetutils.get_friends(your_username) anothers_friends = tweetutils.get_friends(another_username) print "Similarity: %s" % (measures.jaccard_similarity(your_friends, anothers_friends))
def compare_users(self, person_a = None, person_b = None): if person_a and person_b: ########################### # Get the user's friends. # ########################### #### --- Caching seems to fail ... cherrypy black box ... #if person_a in self.user_friend_cache: # print "Loading %s cached friends ... " % person_a # a = self.user_friend_cache[person_a] #else: # a = tweetutils.get_friends(person_a) # self.user_friend_cache[person_a] = a #if person_b in self.user_friend_cache: # print "Loading %s cached friends ... " % person_b # b = self.user_friend_cache[person_b] #else: # b = tweetutils.get_friends(person_b) # self.user_friend_cache[person_b] = b a = tweetutils.get_friends(person_a) b = tweetutils.get_friends(person_b) ################################################## # Get both user's relative sim to other friends. # ################################################## a_friends = tweetutils.get_closest_friends(person_a)[0:5] simsa = [] for (count, friend) in a_friends: ffriends = tweetutils.get_friends(friend) fsim = measures.jaccard_similarity(ffriends, a) simsa.append([friend, fsim]) b_friends = tweetutils.get_closest_friends(person_b)[0:5] simsb = [] for (count, friend) in b_friends: ffriends = tweetutils.get_friends(friend) fsim = measures.jaccard_similarity(ffriends, b) simsb.append([friend, fsim]) shared_friends = a & b ########################## # Get the user hashtags. # ########################## #if person_a in self.user_hashtag_cache: # print "Loading %s cached hashtags ... " % person_a # a_ht = self.user_hashtag_cache[person_a] #else: # a_ht = tweetutils.get_user_hashtags(person_a) #if person_b in self.user_hashtag_cache: # print "Loading %s cached hashtags ... " % person_b # b_ht = self.user_hashtag_cache[person_b] #else: # b_ht = tweetutils.get_user_hashtags(person_b) # self.user_hashtag_cache[person_b] = b_ht a_ht = tweetutils.get_user_hashtags(person_a) b_ht = tweetutils.get_user_hashtags(person_b) ############################ # Process derivative data. # ############################ ht_cnt = len(a_ht & b_ht) ht_shared = a_ht & b_ht if ht_cnt == 0: ht_shared = "." else: ht_shared = ", including %s" % (", ".join(tuple(ht_shared))) sim = round(measures.jaccard_similarity(a,b), 2) ind = mylookup.get_template("result.html") return ind.render(sim=sim, person_a=person_a, person_b=person_b, a_ht = a_ht, b_ht = b_ht, ht_cnt=ht_cnt, ht_shared=ht_shared, simsa=simsa, simsb=simsb, shared_friends = shared_friends) else: ind = mylookup.get_template("generic_message.html") return ind.render(generic_message="Yeah ... you need to enter TWO names, chief.")