Tips_and_Hacks/convert.py

29 lines
1.2 KiB
Python
Raw Normal View History

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)