Skip to content

Instantly share code, notes, and snippets.

@lukaslaobeyer
Created September 9, 2017 03:11
Show Gist options
  • Save lukaslaobeyer/ff9695729746bffb7cbb56a88c5e63e8 to your computer and use it in GitHub Desktop.
Save lukaslaobeyer/ff9695729746bffb7cbb56a88c5e63e8 to your computer and use it in GitHub Desktop.
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