def export_network(user, directory):
    m_texts = bc.network.matrix_directed_weighted(user, 'text')
    m_calls = bc.network.matrix_directed_weighted(user, 'call')
    nb_users = len(m_texts)

    links = []

    for i in range(nb_users):
        for j in range(nb_users):
            source_calls = m_calls[j][i] or 0
            target_calls = m_calls[i][j] or 0
            source_texts = m_texts[j][i] or 0
            target_texts = m_texts[i][j] or 0

            if i < j and source_calls + target_calls + source_texts + target_texts > 0:
                links.append([i, j, (source_calls, target_calls, source_texts, target_texts)])

    names = [user.name] + [i for i in user.network.keys() if i != user.name]
    nodes = set(l[0] for l in links) | set(l[1] for l in links)

    with open(os.path.join(directory, 'nodes.csv'), 'wb') as f:
        f.write('name,no_network_info\n')
        for n in nodes:
            f.write("{},{}\n".format(names[n], int(None in m_texts[n] or m_calls[n] in None)))

    compress_ids = dict(zip(nodes, range(len(nodes))))
    with open(os.path.join(directory, 'links.csv'), 'wb') as f:
        f.write('source,target,source_calls,target_calls,source_texts,target_texts\n')

        for i, j, data in links:
            f.write("{},{},{},{},{},{}\n".format(*(compress_ids[i], compress_ids[j]) + data))
dataset/ETHPy150Open yvesalexandre/bandicoot/bandicoot/special/demo.py/export_network/swapped operands of `in`