Created
April 10, 2012 11:32
-
-
Save gpoulter/2350680 to your computer and use it in GitHub Desktop.
Build Freemind MindMap from Excel file
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/python | |
"""Convert CSV table to MindMap format | |
Usage: python csv_to_mm.py sometable.csv > mymap.mm | |
CSV format is rows representing tree leaves, e.g.: | |
A1, | |
A1,B1 | |
A1,B1,C1 | |
A1,B1,C2 | |
A2,B2 | |
Parses into the following tree: | |
A1 | |
B1 | |
C1 | |
C2 | |
A2 | |
B2 | |
""" | |
# http://pypi.python.org/pypi/xmlbuilder | |
from xmlbuilder import XMLBuilder | |
import csv | |
import sys | |
def csv_to_tree(rows): | |
root = {} | |
for row in rows: | |
tree = root | |
for val in row: | |
if val == '': | |
break | |
if val not in tree: | |
tree[val] = {} | |
tree = tree[val] | |
return root | |
def tree_to_xml(root): | |
xml = XMLBuilder('map', version='0.9.0') | |
def rec_tree(tree, xnode): | |
if tree == {}: | |
return | |
xnode['folded'] = 'true' | |
for key, subtree in tree.iteritems(): | |
rec_tree(subtree, xnode.node(text=key)) | |
xroot = xml.node(text='Categories') | |
rec_tree(root, xroot) | |
xroot['folded'] = 'false' | |
return str(xml) | |
def csv_to_mm_file(inpath): | |
with open(inpath) as instream: | |
rows = [[v.decode('utf-8') for v in row] | |
for row in csv.reader(instream)] | |
print tree_to_xml(csv_to_tree(rows)) | |
if __name__ == "__main__": | |
csv_to_mm_file(sys.argv[1]) |
This worked for me, thanks!
Python27 on Windows 7 with the http://pypi.python.org/pypi/xmlbuilder library installed. Freemind 1.0.0.
It worked for me Ubuntu 14.04- freemind 0.9.
My file had you have to remove this line to make it work.
Thanks a lot gpoulter :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't run. I try with a simple csv file and the mm file created is 0 bytes. Probably I'm doing anything wrong, but I don't know what. The Free Mind version is 0.9.0