From 0611c5ad296ba71742c3639c722dfea245f8e110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczy=C5=84ski?= Date: Fri, 7 Apr 2017 09:46:14 +0200 Subject: [PATCH] Wiki -> Markdown converting --- convert_markdown.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 convert_markdown.py diff --git a/convert_markdown.py b/convert_markdown.py new file mode 100644 index 0000000..30df71b --- /dev/null +++ b/convert_markdown.py @@ -0,0 +1,23 @@ +from os import listdir +from os.path import isfile, join +import os +import sys +import subprocess + +# argv[1] - wiki files directory + +if len(sys.argv) < 2: + print("Argument missing. Usage: python3 moin_convert.py ") +else: + path = sys.argv[1] + if os.path.exists(path): + files = [ f for f in listdir(path) if isfile(join(path, f)) ] + for filename in files: + name, file_extension = os.path.splitext(filename) + if file_extension == ".txt": + print("Converting %s/%s" % (path, filename)) + options = ['pandoc','-f','mediawiki','-t','markdown','-s',join(path,filename),'-o',join(path,name + ".md")] + subprocess.call(options) + else: + print("Error: the path specified is invalid") +