Create script

This commit is contained in:
PAlexanderFranklin 2024-02-09 10:10:33 -08:00
parent be98cb93d8
commit 6eb6faf747

38
main.py Normal file
View File

@ -0,0 +1,38 @@
import os
def addVerses(text):
lines = text.split("\n")
newLines = [
f"{index - 2} {line}"
for index, line in enumerate(lines, 1)
if len(line) > 0 and index > 2
]
return "\n".join([lines[0][:-1] + " " + lines[1][:-1] + " "] + newLines)
def process_all_files(source_directory, destination_directory):
try:
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)
with open(source_path, "r") as text_file:
content = text_file.read()
modified_content = addVerses(content)
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)
except FileNotFoundError:
print(f"Directory not found: {source_directory}")
except Exception as e:
print(f"An error occurred: {e}")
source_directory = "sourceFiles"
destination_directory = "output"
process_all_files(source_directory, destination_directory)