Pass in a user_id and you will be returned a generator of friendship 
    tuples (user_id, friend_id). By default it will return the friend
    of a friend network (level=2), but you can expand this by settings the 
    level parameter to either another number. But beware, it could run for a 
    while!

def friendships(user_id, level=2):
    """
    Pass in a user_id and you will be returned a generator of friendship 
    tuples (user_id, friend_id). By default it will return the friend
    of a friend network (level=2), but you can expand this by settings the 
    level parameter to either another number. But beware, it could run for a 
    while!
    """

    logging.info("getting friends for user %s", user_id)
    level -= 1
    try:
        for friend_id in t.friend_ids(user_id):
            yield (user_id, friend_id)
            if level > 0:
                yield from friendships(friend_id, level)
    except requests.exceptions.HTTPError as e:
        if e.response.status_code == 401:
            logging.error("can't get friends for protected user %s", user_id)
        else:
            raise(e)