Skip to content

Instantly share code, notes, and snippets.

@kerin
Created July 18, 2014 10:38
Show Gist options
  • Save kerin/20f6472129e7d4a956d5 to your computer and use it in GitHub Desktop.
Save kerin/20f6472129e7d4a956d5 to your computer and use it in GitHub Desktop.
#!/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