Created
March 16, 2020 15:38
-
-
Save zelinskiy/aeb8c283890b04aefc61aabe223adca6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import listdir | |
DIR = "./Martyrologium1960" | |
months = ["_Jan_", "_Feb_", "_Mar_", "_Apr_", "_May_", "_Jun_", "_Jul_", "_Aug_", | |
"_Sep_", "_Oct_", "_Nov_", "_Dec_"] | |
files = [] | |
for f in listdir(DIR): | |
if f.endswith(".txt"): | |
with open(DIR + "/" + f, 'r', encoding = "ISO-8859-1") as file: | |
data = file.read() | |
data = data.split("\n_\n") | |
header, paragraphs = data[0], data[1].split("\n") | |
paragraphs = list(filter(lambda p: len(p) > 0, paragraphs)) | |
f = f.replace(".txt", "") | |
f = f.split("-") | |
m, d = f[0], f[1] | |
files.append((m, d, header, paragraphs)) | |
files.sort(key=lambda t: (t[0], t[1])) | |
out = "" | |
for m, d, hdr, pars in files: | |
out += "\\martday{" + d + " " + months[int(m) - 1] + "}{" + hdr + "}\n\n" | |
for p in pars: | |
out += "\\martentry{" + p + "}\n\n" | |
out += "\\endmartday\n\n" | |
with open("out.txt", 'w', encoding = "ISO-8859-1") as file: | |
file.write(out) | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment