|
| 1 | +""" |
| 2 | +================================================================================ |
| 3 | +<PROJECT OR SCRIPT TITLE> |
| 4 | +================================================================================ |
| 5 | +Author : Breno Farias da Silva |
| 6 | +Created : <YYYY-MM-DD> |
| 7 | +Description : |
| 8 | + <Provide a concise and complete overview of what this script does.> |
| 9 | + <Mention its purpose, scope, and relevance to the larger project.> |
| 10 | +
|
| 11 | + Key features include: |
| 12 | + - <Feature 1 — e.g., automatic data loading and preprocessing> |
| 13 | + - <Feature 2 — e.g., model training and evaluation> |
| 14 | + - <Feature 3 — e.g., visualization or report generation> |
| 15 | + - <Feature 4 — e.g., logging or notification system> |
| 16 | + - <Feature 5 — e.g., integration with other modules or datasets> |
| 17 | +
|
| 18 | +Usage: |
| 19 | + 1. <Explain any configuration steps before running, such as editing variables or paths.> |
| 20 | + 2. <Describe how to execute the script — typically via Makefile or Python.> |
| 21 | + $ make <target> or $ python <script_name>.py |
| 22 | + 3. <List what outputs are expected or where results are saved.> |
| 23 | +
|
| 24 | +Outputs: |
| 25 | + - <Output file or directory 1 — e.g., results.csv> |
| 26 | + - <Output file or directory 2 — e.g., Feature_Analysis/plots/> |
| 27 | + - <Output file or directory 3 — e.g., logs/output.txt> |
| 28 | +
|
| 29 | +TODOs: |
| 30 | + - <Add a task or improvement — e.g., implement CLI argument parsing.> |
| 31 | + - <Add another improvement — e.g., extend support to Parquet files.> |
| 32 | + - <Add optimization — e.g., parallelize evaluation loop.> |
| 33 | + - <Add robustness — e.g., error handling or data validation.> |
| 34 | +
|
| 35 | +Dependencies: |
| 36 | + - Python >= <version> |
| 37 | + - <Library 1 — e.g., pandas> |
| 38 | + - <Library 2 — e.g., numpy> |
| 39 | + - <Library 3 — e.g., scikit-learn> |
| 40 | + - <Library 4 — e.g., matplotlib, seaborn, tqdm, colorama> |
| 41 | +
|
| 42 | +Assumptions & Notes: |
| 43 | + - <List any key assumptions — e.g., last column is the target variable.> |
| 44 | + - <Mention data format — e.g., CSV files only.> |
| 45 | + - <Mention platform or OS-specific notes — e.g., sound disabled on Windows.> |
| 46 | + - <Note on output structure or reusability.> |
| 47 | +""" |
| 48 | + |
| 49 | +import atexit # For playing a sound when the program finishes |
| 50 | +import os # For running a command in the terminal |
| 51 | +import platform # For getting the operating system name |
| 52 | +from colorama import Style # For coloring the terminal |
| 53 | + |
| 54 | +# Macros: |
| 55 | +class BackgroundColors: # Colors for the terminal |
| 56 | + CYAN = "\033[96m" # Cyan |
| 57 | + GREEN = "\033[92m" # Green |
| 58 | + YELLOW = "\033[93m" # Yellow |
| 59 | + RED = "\033[91m" # Red |
| 60 | + BOLD = "\033[1m" # Bold |
| 61 | + UNDERLINE = "\033[4m" # Underline |
| 62 | + CLEAR_TERMINAL = "\033[H\033[J" # Clear the terminal |
| 63 | + |
| 64 | +# Execution Constants: |
| 65 | +VERBOSE = False # Set to True to output verbose messages |
| 66 | + |
| 67 | +# Sound Constants: |
| 68 | +SOUND_COMMANDS = {"Darwin": "afplay", "Linux": "aplay", "Windows": "start"} # The commands to play a sound for each operating system |
| 69 | +SOUND_FILE = "./.assets/Sounds/NotificationSound.wav" # The path to the sound file |
| 70 | + |
| 71 | +# RUN_FUNCTIONS: |
| 72 | +RUN_FUNCTIONS = { |
| 73 | + "Play Sound": True, # Set to True to play a sound when the program finishes |
| 74 | +} |
| 75 | + |
| 76 | +# Functions Definitions: |
| 77 | + |
| 78 | +def verbose_output(true_string="", false_string=""): |
| 79 | + """ |
| 80 | + Outputs a message if the VERBOSE constant is set to True. |
| 81 | +
|
| 82 | + :param true_string: The string to be outputted if the VERBOSE constant is set to True. |
| 83 | + :param false_string: The string to be outputted if the VERBOSE constant is set to False. |
| 84 | + :return: None |
| 85 | + """ |
| 86 | + |
| 87 | + if VERBOSE and true_string != "": # If the VERBOSE constant is set to True and the true_string is set |
| 88 | + print(true_string) # Output the true statement string |
| 89 | + elif false_string != "": # If the false_string is set |
| 90 | + print(false_string) # Output the false statement string |
| 91 | + |
| 92 | +def verify_filepath_exists(filepath): |
| 93 | + """ |
| 94 | + Verify if a file or folder exists at the specified path. |
| 95 | +
|
| 96 | + :param filepath: Path to the file or folder |
| 97 | + :return: True if the file or folder exists, False otherwise |
| 98 | + """ |
| 99 | + |
| 100 | + verbose_output(f"{BackgroundColors.GREEN}Verifying if the file or folder exists at the path: {BackgroundColors.CYAN}{filepath}{Style.RESET_ALL}") # Output the verbose message |
| 101 | + |
| 102 | + return os.path.exists(filepath) # Return True if the file or folder exists, False otherwise |
| 103 | + |
| 104 | +def play_sound(): |
| 105 | + """ |
| 106 | + Plays a sound when the program finishes and skips if the operating system is Windows. |
| 107 | +
|
| 108 | + :param: None |
| 109 | + :return: None |
| 110 | + """ |
| 111 | + |
| 112 | + current_os = platform.system() # Get the current operating system |
| 113 | + if current_os == "Windows": # If the current operating system is Windows |
| 114 | + return # Do nothing |
| 115 | + |
| 116 | + if verify_filepath_exists(SOUND_FILE): # If the sound file exists |
| 117 | + if current_os in SOUND_COMMANDS: # If the platform.system() is in the SOUND_COMMANDS dictionary |
| 118 | + os.system(f"{SOUND_COMMANDS[current_os]} {SOUND_FILE}") # Play the sound |
| 119 | + else: # If the platform.system() is not in the SOUND_COMMANDS dictionary |
| 120 | + print(f"{BackgroundColors.RED}The {BackgroundColors.CYAN}{current_os}{BackgroundColors.RED} is not in the {BackgroundColors.CYAN}SOUND_COMMANDS dictionary{BackgroundColors.RED}. Please add it!{Style.RESET_ALL}") |
| 121 | + else: # If the sound file does not exist |
| 122 | + print(f"{BackgroundColors.RED}Sound file {BackgroundColors.CYAN}{SOUND_FILE}{BackgroundColors.RED} not found. Make sure the file exists.{Style.RESET_ALL}") |
| 123 | + |
| 124 | +def main(): |
| 125 | + """ |
| 126 | + Main function. |
| 127 | +
|
| 128 | + :param: None |
| 129 | + :return: None |
| 130 | + """ |
| 131 | + |
| 132 | + print(f"{BackgroundColors.CLEAR_TERMINAL}{BackgroundColors.BOLD}{BackgroundColors.GREEN}Welcome to the {BackgroundColors.CYAN}Main Template Python{BackgroundColors.GREEN} program!{Style.RESET_ALL}", end="\n\n") # Output the welcome message |
| 133 | + |
| 134 | + print(f"\n{BackgroundColors.BOLD}{BackgroundColors.GREEN}Program finished.{Style.RESET_ALL}") # Output the end of the program message |
| 135 | + |
| 136 | + atexit.register(play_sound) if RUN_FUNCTIONS["Play Sound"] else None # Register the play_sound function to be called when the program finishes |
| 137 | + |
| 138 | +if __name__ == "__main__": |
| 139 | + """ |
| 140 | + This is the standard boilerplate that calls the main() function. |
| 141 | +
|
| 142 | + :return: None |
| 143 | + """ |
| 144 | + |
| 145 | + main() # Call the main function |
0 commit comments