#!/usr/bin/env python # Script Name: process-stage-4 import os import subprocess from pyfiglet import Figlet from halo import Halo def find_project_root(current_path): """Find the project root by locating the 'bin' directory.""" while current_path != os.path.dirname(current_path): if os.path.basename(current_path) == 'bin': return os.path.dirname(current_path) current_path = os.path.dirname(current_path) raise FileNotFoundError("Could not find 'bin' directory in the path hierarchy.") # Define the paths based on the project details script_path = os.path.abspath(__file__) PROJECT_ROOT = find_project_root(script_path) BIN_STAGE_4_DIR = os.path.join(PROJECT_ROOT, 'bin', 'stage-4') BIN_DIR = os.path.join(PROJECT_ROOT, 'bin') def run_scripts(): """Run the specified scripts in order.""" scripts = [ os.path.join(BIN_STAGE_4_DIR, "prepare-stage-4.py"), os.path.join(BIN_STAGE_4_DIR, "reshift-terms.py"), os.path.join(BIN_STAGE_4_DIR, "strip-neg-terms-from-unknown-cols.py"), os.path.join(BIN_STAGE_4_DIR, "strip-neg-patterns-from-unknown-cols.py"), os.path.join(BIN_STAGE_4_DIR, "delete-sponsored-listings.py"), os.path.join(BIN_DIR, "remove-empty-columns.py"), os.path.join(BIN_DIR, "report-unknowns.py") ] # Run scripts that do not require arguments for script in scripts[:-2]: subprocess.run(["python", script], check=True) # Run scripts that require the 'stage-4' argument subprocess.run(["python", scripts[-2], "stage-4"], check=True) subprocess.run(["python", scripts[-1], "stage-4"], check=True) def main(): figlet = Figlet(font='slant') script_name = "process-stage-4".replace("-", " ").title() print(figlet.renderText(script_name)) print("Running scripts for Stage 4...\n") run_scripts() final_spinner = Halo(spinner='dots', color='green') final_spinner.start() final_spinner.succeed("All scripts completed.") if __name__ == '__main__': main()