summaryrefslogtreecommitdiff
path: root/csv2wiki/csv2wiki.py
blob: 7bf0e5bcd450b61e42325eba311c677535a66102 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 "|}"