From 6eb6faf7477c9da9bac068d1b097bcaa6c0b303c Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Fri, 9 Feb 2024 10:10:33 -0800 Subject: [PATCH] Create script --- main.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..2039639 --- /dev/null +++ b/main.py @@ -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)