def generate_network(user=None, reset=False):
    """
    Assemble the network connections for a given user
    """

    token = collect_token()

    try:
        gh = login(token=token)
        root_user = gh.user(user)
    except Exception, e:
        # Failed to login using the token, github3.models.GitHubError
        raise e

    graph_nodes = []
    graph_edges = []

    username = user if user is not None else root_user.login

    if not is_cached(username_to_file(username)) or reset:
        graph_nodes.append(username)

        # @TODO: take care of the 'rate limit exceeding' if imposed
        try:
            for person in gh.iter_following(username):
                graph_nodes.append(str(person))
                graph_edges.append((root_user.login, str(person)))

            for i in range(1, root_user.following):
                user = gh.user(graph_nodes[i])
                user_following_edges = [(user.login, str(person)) for person in gh.iter_following(
                    user) if str(person) in graph_nodes]
                graph_edges += user_following_edges
        except Exception, e:
            raise e

        generate_gml(username, graph_nodes, graph_edges, True)
    else:
        reuse_gml(username)

    return username
def generate_network ( user = None , reset = False ) : token = collect_token ( ) try : gh = login ( token = token ) root_user = gh . user ( user ) except Exception , e : raise e graph_nodes = [ ] graph_edges = [ ] username = user if user is not None else root_user . login if not is_cached ( username_to_file ( username ) ) or reset : graph_nodes . append ( username ) try : for person in gh . iter_following ( username ) : graph_nodes . append ( str ( person ) ) graph_edges . append ( ( root_user . login , str ( person ) ) ) for i in range ( 1 , root_user . following ) : user = gh . user ( graph_nodes [ i ] ) user_following_edges = [ ( user . login , str ( person ) ) for person in gh . iter_following ( user ) if str ( person ) in graph_nodes ] graph_edges += user_following_edges except Exception , e : raise e generate_gml ( username , graph_nodes , graph_edges , True ) else : reuse_gml ( username ) return username
Assemble the network connections for a given user