Combine books, remove "chapter" from Psalms, add books to Psalms, add reading output
This commit is contained in:
parent
c82402a60f
commit
e8f1a1578d
65
main.py
65
main.py
@ -4,35 +4,76 @@ import os
|
||||
def addVerses(text):
|
||||
lines = text.split("\n")
|
||||
newLines = [
|
||||
f"{index - 2} {line}"
|
||||
f"{index - 1} {line}"
|
||||
for index, line in enumerate(lines, 1)
|
||||
if len(line) > 0 and index > 2
|
||||
if len(line) > 0 and index > 1
|
||||
]
|
||||
|
||||
return "\n".join([lines[0][:-1] + " " + lines[1][:-1] + " "] + newLines)
|
||||
return "\n".join([lines[0]] + newLines)
|
||||
|
||||
|
||||
def process_all_files(source_directory, destination_directory):
|
||||
def process_all_files(source_directory, verse_directory, reading_directory):
|
||||
try:
|
||||
bookDict = {}
|
||||
for filename in os.listdir(source_directory):
|
||||
if filename.endswith(".txt"):
|
||||
source_path = os.path.join(source_directory, filename)
|
||||
destination_path = os.path.join(destination_directory, filename)
|
||||
# destination_path = os.path.join(destination_directory, filename)
|
||||
|
||||
with open(source_path, "r") as text_file:
|
||||
content = text_file.read()
|
||||
modified_content = addVerses(content)
|
||||
if content is not None:
|
||||
lines = content.split("\n")
|
||||
if filename[12:15] == "PSA":
|
||||
if filename[16:19] == "001":
|
||||
lines[0] = " Book 1, Psalm."
|
||||
elif filename[16:19] == "042":
|
||||
lines[0] = " Book 2, Psalm."
|
||||
elif filename[16:19] == "073":
|
||||
lines[0] = " Book 3, Psalm."
|
||||
elif filename[16:19] == "090":
|
||||
lines[0] = " Book 4, Psalm."
|
||||
elif filename[16:19] == "107":
|
||||
lines[0] = " Book 5, Psalm."
|
||||
else:
|
||||
lines[0] = " Psalm."
|
||||
lines[1] = lines[1].split(" ")[1]
|
||||
|
||||
modified_content = "\n".join(
|
||||
[lines[0][:-1] + " " + lines[1][:-1] + " "]
|
||||
+ lines[2:]
|
||||
+ [""]
|
||||
)
|
||||
# modified_content = addVerses(content)
|
||||
# modified_content = "hi"
|
||||
|
||||
if modified_content is not None:
|
||||
# Write the modified content to a new file in the destination directory
|
||||
with open(destination_path, "w") as modified_file:
|
||||
modified_file.write(modified_content)
|
||||
# with open(destination_path, "w") as modified_file:
|
||||
# modified_file.write(modified_content)
|
||||
# print(filename[16:18])
|
||||
if not filename[8:15] in bookDict:
|
||||
bookDict[filename[8:15]] = ["" for num in range(151)]
|
||||
|
||||
bookDict[filename[8:15]][
|
||||
int(filename.split("_")[3])
|
||||
] = modified_content
|
||||
for book, chapterList in bookDict.items():
|
||||
chapterList = [chapter[1:] for chapter in chapterList if chapter != ""]
|
||||
destination_path = os.path.join(reading_directory, book + "_read.txt")
|
||||
with open(destination_path, "w") as modified_file:
|
||||
modified_file.write("".join(chapterList))
|
||||
chapterList = [addVerses(chapter) for chapter in chapterList]
|
||||
destination_path = os.path.join(verse_directory, book + ".txt")
|
||||
with open(destination_path, "w") as modified_file:
|
||||
modified_file.write("\n\n".join(chapterList))
|
||||
# print(bookDict["092_1JN"])
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Directory not found: {source_directory}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
|
||||
source_directory = "inputFiles"
|
||||
destination_directory = "output"
|
||||
process_all_files(source_directory, destination_directory)
|
||||
verse_directory = "numberedOutput"
|
||||
reading_directory = "readingOutput"
|
||||
process_all_files(source_directory, verse_directory, reading_directory)
|
||||
|
Loading…
Reference in New Issue
Block a user