summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-09-08 09:52:20 +0100
committerFreeArtMan <dos21h@gmail.com>2015-09-08 09:52:20 +0100
commit2c113ccbfd5b73866a91a2de261aa9590ca8b1b6 (patch)
treecdcc2dfdf274cae5b7d21c93f27b1a1767807291
parent892dad5e3018ca1bd998c71ee32a72d725e92047 (diff)
downloadcode-snippets-2c113ccbfd5b73866a91a2de261aa9590ca8b1b6.tar.gz
code-snippets-2c113ccbfd5b73866a91a2de261aa9590ca8b1b6.zip
csv2wiki converts csv file to wiki table
-rw-r--r--README.md2
-rw-r--r--csv2wiki/csv2wiki.py35
2 files changed, 36 insertions, 1 deletions
diff --git a/README.md b/README.md
index f3fb542..09904a3 100644
--- a/README.md
+++ b/README.md
@@ -3,4 +3,4 @@ some small code snippets in any language
cowsay - prints some ascci pic with your text
utf8_count - count character statistics in file (UTF-8 supported)
-
+csv2wiki - formats csv file to wiki table
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