#/usr/bin/env python # Your infile should be a tab-delimited file called sitemap.tsv # It will output a file called sitemap.dot # To convert to a graph with GraphViz, use: # dot -Tpng sitemap.dot -o sitemap.png # See http://tips.webdesign10.com/graphviz_information_architecture.html # Based on the function dot_create_dot_file from this code: # http://urlgreyhot.com/graphviz/index.phps # Which can be tried out at http://urlgreyhot.com/graphviz/ infilename = "sitemap.tsv" outfilename = "sitemap.dot" infile = open( infilename, "r" ) dotlines = "" for line in infile: # process lines line = line.split("\t") # infile format is tab-delimited in these columns: # ID/PARENT/LABEL datid = line[0].strip() datparent = line[1].strip() datlabel = line[2].strip('" \n') # output if datid != '': dotlines += """ %s [ label ="%s", fontsize="10", fontname="Sans" ]\n """ % (datid, datlabel) if datid != datparent: dotlines += """ %s -> %s\n""" % (datparent, datid) # Prepare dot options dotfile = """digraph G {\n node [ shape="box", color=gray, fontname="Sans", fontsize="10", fontcolor="#333333" ]\n edge [ color=gray, arrowhead=none ]\n""" # Add data dotfile += dotlines dotfile += "}" # Write file outfile = open(outfilename, "w") outfile.write(dotfile) # Close files infile.close() outfile.close()