2024-02-09 18:10:33 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def addVerses(text):
|
|
|
|
lines = text.split("\n")
|
|
|
|
newLines = [
|
2024-02-13 16:19:27 +00:00
|
|
|
f"{index - 1} {line}"
|
2024-02-09 18:10:33 +00:00
|
|
|
for index, line in enumerate(lines, 1)
|
2024-02-13 16:19:27 +00:00
|
|
|
if len(line) > 0 and index > 1
|
2024-02-09 18:10:33 +00:00
|
|
|
]
|
|
|
|
|
2024-02-13 16:19:27 +00:00
|
|
|
return "\n".join([lines[0]] + newLines)
|
2024-02-09 18:10:33 +00:00
|
|
|
|
|
|
|
|
2024-02-13 16:19:27 +00:00
|
|
|
def process_all_files(source_directory, verse_directory, reading_directory):
|
2024-02-09 18:10:33 +00:00
|
|
|
try:
|
2024-02-13 16:19:27 +00:00
|
|
|
bookDict = {}
|
2024-02-09 18:10:33 +00:00
|
|
|
for filename in os.listdir(source_directory):
|
|
|
|
if filename.endswith(".txt"):
|
|
|
|
source_path = os.path.join(source_directory, filename)
|
2024-02-13 16:19:27 +00:00
|
|
|
# destination_path = os.path.join(destination_directory, filename)
|
2024-02-09 18:10:33 +00:00
|
|
|
|
|
|
|
with open(source_path, "r") as text_file:
|
|
|
|
content = text_file.read()
|
2024-02-13 16:19:27 +00:00
|
|
|
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"
|
2024-02-09 18:10:33 +00:00
|
|
|
|
|
|
|
if modified_content is not None:
|
|
|
|
# Write the modified content to a new file in the destination directory
|
2024-02-13 16:19:27 +00:00
|
|
|
# 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"])
|
|
|
|
|
2024-02-09 18:10:33 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
print(f"Directory not found: {source_directory}")
|
|
|
|
|
|
|
|
|
2024-02-13 14:51:40 +00:00
|
|
|
source_directory = "inputFiles"
|
2024-02-13 16:19:27 +00:00
|
|
|
verse_directory = "numberedOutput"
|
|
|
|
reading_directory = "readingOutput"
|
|
|
|
process_all_files(source_directory, verse_directory, reading_directory)
|