Newer
Older
from anytree import Node, RenderTree
#from anytree.exporter import DotExporter
content = json.loads(open('help.json').read())
d = {}
def add_child(key, path):
global d
item = content[key]
if 'action' in item:
n = Node(item["action"], parent=d[path])
n = Node("{} ({})".format(content[option]["title"],content[option]["description"]), parent=d[path])
n_path = path + "-" + option
d[n_path] = n
add_child(option, n_path)
root = Node("root")
d["root"]=root
add_child("root", "root")
for pre, fill, node in RenderTree(root):
print("%s%s" % (pre, node.name))
#DotExporter(root).to_picture("help.png")