Ejemplo n.º 1
0
def find_missing_friends(members, known):
    """(list)->None
    dsc: find user names that no friend list is found for them
    """
    for member in members:
        if member not in known:
            all_friends = friends.find_friends(member)
            known.update({member: all_friends})
            find_friends_recursive(all_friends, known)
Ejemplo n.º 2
0
def find_friends_bfs(members, known):
    """(list, dict)->list
    dsc: find first level of friends and return known stage
    """
    i = 0
    users_to_find_next = []
    if members.__class__ == list:
        for name in members:
            i += 1
            print '%d of %d, find friends for %s' % (i, len(members), name)
            all_friends = friends.find_friends(name)
            if all_friends.__class__ == list and all_friends:
                users_to_find_next.extend(all_friends)
    return list(set(users_to_find_next))
Ejemplo n.º 3
0
def get_adjacancy_list(members):
    """(list)-> dict
    dsc: returns a list of friends and for given members
    """
    result = {}
    while members:
        members = list(set(members))
        name = members.pop()
        print len(members), name
        if name not in result:
            all_friends = friends.find_friends(name)
            result.update({name: all_friends})
            if all_friends.__class__ == list and all_friends:
                members.extend(all_friends)
    return result
Ejemplo n.º 4
0
def find_friends_recursive(members, known):
    """(list)->None
    dsc: gets all members of a given book and returns friends
    for each one recursively
    """
    i = 0
    #print members
    if members.__class__ == list:
        for name in members:
            i += 1
            print '%d of %d' % (i, len(members))
            print "find friends for %s" % name
            all_friends = friends.find_friends(name)
            if all_friends.__class__ == list and all_friends:
                if name not in known:
                    print "continue with %s" % str(all_friends)
                    known.update({name: all_friends})
                    find_friends_recursive(all_friends, known)
            else:
                print 'done for %s' % name
        print "finished successfully! %d" % len(members)