def get_edge_weight(G, node1, node2, weight_attribute="weight"):
    """
    Get Edge Weight

    Returns edge weight for edge in G from node1 to node2
    If edge exists and has weight_attribute, this value is returned.
    If edge exists but has not weight_attribute, 1 is returned.
    Otherwise 0 is returned

    Input
    -----
    G - networkx graph
    node1 - source node
    node2 - target node
    weight_attribute='weight' - attribute of edge containing weight value

    Return
    ------
    edge weight, 1 if edge exists but no weight attribute exists, 0 otherwise.

    """
    edge_data = G.get_edge_data(node1, node2)
    if edge_data is None:
        return 0
    elif weight_attribute in edge_data:
        return edge_data[weight_attribute]
    else:
        return 1