DONE

Get graph's island centers

%3 cluster_6eed20c1_d778_4b23_a04e_fc245ad8eccd Get graph's island centers _0873a209_b9df_4bf3_b65e_2f425c5a2adc Librarian / Personal Library _ea48ec1d_f9d4_4fb7_b39a_faa7b6e2ba95 Notes index __0:cluster_6eed20c1_d778_4b23_a04e_fc245ad8eccd->_0873a209_b9df_4bf3_b65e_2f425c5a2adc __1:cluster_6eed20c1_d778_4b23_a04e_fc245ad8eccd->_ea48ec1d_f9d4_4fb7_b39a_faa7b6e2ba95
graph_path = '/home/kenkeiras/repos/codigoparallevar/_gen/notes/graph.json'
ignored_nodes = (
    # Index
    'ea48ec1d-f9d4-4fb7-b39a-faa7b6e2ba95',
    '096ddc7b-e98e-40bf-b0d0-0b447d54265c',
    # This note
    '6eed20c1-d778-4b23-a04e-fc245ad8eccd',
)

import matplotlib.pyplot as plt, json, networkx

data = json.load(open(graph_path))

graph = networkx.DiGraph()
for k, v in data.items():
    for l in v['links']:
        graph.add_edge(k, l['target'].split(':')[-1])

for node_id in ignored_nodes:
    graph.remove_node(node_id)

subgraphs = list(networkx.connected_components(graph.to_undirected()))

centers = []
for subgraph in subgraphs:
    sg = networkx.DiGraph()
    any_found = False
    for k in subgraph:
        if k not in data:
            continue
        v = data[k]
        for l in v['links']:
            sg.add_edge(k, l['target'].split(':')[-1])
            any_found = True

    if not any_found:
        continue
    sg_centers = networkx.center(sg.to_undirected())
    if data.get(sg_centers[0], {}).get('title'):
        centers.append(f'[[id:{sg_centers[0]}][{data.get(sg_centers[0], {})["title"]}]]')
return '\n'.join(centers)