From 2c113ccbfd5b73866a91a2de261aa9590ca8b1b6 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 8 Sep 2015 09:52:20 +0100 Subject: csv2wiki converts csv file to wiki table --- csv2wiki/csv2wiki.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 csv2wiki/csv2wiki.py (limited to 'csv2wiki') diff --git a/csv2wiki/csv2wiki.py b/csv2wiki/csv2wiki.py new file mode 100644 index 0000000..7bf0e5b --- /dev/null +++ b/csv2wiki/csv2wiki.py @@ -0,0 +1,35 @@ +import csv +import os.path +import sys + +if len( sys.argv ) != 2: + print "csv2wiki [FILE]" + sys.exit(0) + +fname = sys.argv[1] + +if not os.path.exists( fname ): + print "Cannot find file ", fname + sys.exit(0) + +#if there row will be error +first_row = True +with open(fname,"rb") as f: + cr = csv.reader( f, delimiter=',', quotechar='"' ) + for row in cr: + #special case for first row + if first_row: + print """ +{| class="wikitable sortable" +|- +""" + for cell in row: + print "!|",cell + first_row = False + continue + + print "|-" + for cell in row: + print "||", cell + +print "|}" \ No newline at end of file -- cgit v1.2.3