CSV to Html
import csv
def csvToHtml():
part1 = " \n \n"
" \n \n"
"
" <meta charset="UTF-8"> \n \n"
" "
part2 = "</title> \n \n" \
" <script src=\"TRAViz/traviz-min.js\"> </script> \n \n" \
" <link rel=\"stylesheet\" type=\"text/css\" href=\"TRAViz/traviz.css\"></link> \n \n" \
" </head> \n \n" \
" <body> \n \n" \
" <h2>"
part3 = "</h2> \n \n" \
" <div id=\"containerDiv\"></div> \n \n" \
" <script type=\"text/javascript\"> \n \n" \
" var traviz = new TRAViz(\"containerDiv\",{ \n \n" \
" editDistance: 0.3, \n \n" \
" connectionType: 'majority' \n \n \n" \
" }); \n" \
" traviz.align([{ \n \n" \
" edition: "
part4 = ", \n" \
" text: "
part5 =" },{ \n \n" \
" edition: "
part6 =", \n \n" \
" text: "
part7 = "\n }]); \n \n" \
" traviz.visualize(); \n \n" \
" </script> \n \n" \
" </body> \n \n" \
"</html> \n "
writeHtml(part1,part2,part3,part4,part5,part6,part7)
def writeHtml(part1,part2,part3,part4,part5,part6,part7):
with open('C:\Markus\ergleich.csv', encoding="utf8", newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader)
for row in reader:
with open("" + row[0] + ".html", 'w', encoding="utf8") as f:
f.write(""+part1 + row[1]+ part2 + row[1] + part3 + "'" +row[2] + "'" +"\n" + part4 + "'" +row[3].replace("'", "\\'") + "'" +"\n \n" + part5 + "'"+row[4]+ "'" + part6 +"'" + row[5].replace("'", "\\'") + "'" +"\n" + part7)
if name == 'main': csvToHtml()