Wiki -> Markdown converting

This commit is contained in:
Maciej Wilczyński 2017-04-07 09:46:14 +02:00
parent f42ee7010d
commit 0611c5ad29

23
convert_markdown.py Normal file
View File

@ -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 <wiki content dir>")
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")