Convert.py Version .1

This is a little Python script to take DokuWiki OBS Markdown files and convert them into translationStudio project format. There is still some work to be done (no manifest is generated, and there are extraneous 0.txt files (although that second bug should be relatively easy to squash). After creating a same-book-same-language project the files generated by this script can be simply copied over to the targetTranslations folder in which contains the good project.
This commit is contained in:
John Wood 2017-08-16 16:44:17 +00:00
parent d59ca0fab8
commit 5fe717dc69
1 changed files with 29 additions and 0 deletions

29
convert.py Normal file
View File

@ -0,0 +1,29 @@
import os
import re
#os.chroot(".\\");
for filename in os.listdir("."):
if filename.endswith(".md"):
filenum = 00;
newpath = filename.replace(".md","");
newpath = "/Users/jdwood/Downloads/tpi_obs/content/" + newpath;
if not os.path.exists(newpath):
os.makedirs(newpath)
newpath = newpath + "/";
with open(filename) as mdfile:
print "Working with " + filename + ".\n"
for line in mdfile:
if re.match("\!\[OBS",line):
filenum = filenum + 1
elif re.match("#",line):
myTitle = newpath + "title.txt"
with open(myTitle, "a+") as newfile:
newfile.write(line.replace("#",""));
elif re.match("_",line):
myRef = newpath + "reference.txt"
with open(myRef, "a+") as newfile:
newfile.write(line.replace("_",""));
else:
myNewFile = newpath + "{:0>2d}".format(filenum) + ".txt"
with open(myNewFile, "a+") as newfile:
newfile.write(line)