2017-04-07 09:46:14 +02:00
|
|
|
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:
|
2017-04-07 09:48:37 +02:00
|
|
|
print("Argument missing. Usage: python3 convert_markdown.py <wiki content dir>")
|
2017-04-07 09:46:14 +02:00
|
|
|
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")
|
|
|
|
|