Created
July 18, 2014 10:38
-
-
Save kerin/20f6472129e7d4a956d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python | |
| import opml | |
| from uuid import uuid4 | |
| from pygraphml.GraphMLParser import GraphMLParser | |
| from pygraphml.Graph import Graph | |
| def handle_outline(outline, parent_node=None): | |
| id = uuid4() if parent_node else 'root' | |
| outline_node = g.add_node(id) | |
| outline_node['title'] = outline.text.encode('utf-8') | |
| if parent_node: | |
| g.add_edge(parent_node, outline_node, directed=True) | |
| for child in outline: | |
| handle_outline(child, outline_node) | |
| opml_raw = open('Scope testing for operators v0.1.opml', 'r').read() | |
| doc = opml.from_string(opml_raw) | |
| g = Graph() | |
| handle_outline(doc[0]) | |
| parser = GraphMLParser() | |
| parser.write(g, "diagnosis.graphml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment