Created
September 9, 2017 03:11
-
-
Save lukaslaobeyer/ff9695729746bffb7cbb56a88c5e63e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import subprocess | |
G = nx.DiGraph() | |
lists = [] | |
def from_blanche(name): | |
cmd = ['blanche', name, '-l'] | |
out = subprocess.check_output(cmd).decode('ascii') | |
return [line[5:].strip() for line in out.splitlines()] | |
def sublists(name): | |
subs = from_blanche(name) | |
[G.add_node(sub) for sub in subs] | |
return [(name, sub) for sub in subs] | |
with open("my-lists") as listfile: | |
for line in listfile: | |
lists += [line.strip()] | |
G.add_nodes_from(lists) | |
for name in lists: | |
G.add_edges_from(sublists(name)) | |
print(G.nodes()) | |
nx.write_gexf(G, 'lists.gexf', prettyprint=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment