From 11a2b3a1a09e463be074a5699859ffca029afd21 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 28 Apr 2025 17:38:15 -0400 Subject: [PATCH] ANSI colors: green, yellow, and red added. --- delibs.py | 23 ++++++++++++++++++++--- get_dups.sh | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/delibs.py b/delibs.py index ba9427f..0c214fd 100644 --- a/delibs.py +++ b/delibs.py @@ -16,6 +16,9 @@ use_ANSI_Colors = True # ANSI escape codes for colors WHITE = "\033[97m" +BRIGHT_GREEN = "\033[92m" +BRIGHT_YELLOW = "\033[93m" +BRIGHT_RED = "\033[91m" RESET = "\033[0m" start = time.perf_counter() @@ -29,12 +32,25 @@ def exit_handler(signum, frame): # CTRL+C will Exit NOW!!! signal.signal(signal.SIGINT, exit_handler) +def get_color_for_timer(total): + match total: + case x if x < 1: # 0.x + return BRIGHT_GREEN + case x if 1 <= x <= 7: # Matches 1 to 7 + return WHITE + case x if x >= 10: + return BRIGHT_RED + case _: + return BRIGHT_YELLOW #8-9 + def exit_timer(level): end = time.perf_counter() + total_time = end - start if use_ANSI_Colors == True: - print(f"{WHITE}⏱ Execution took {end - start:.4f} seconds{RESET}") + use_color = get_color_for_timer(total_time) + print(f"{use_color}⏱ Execution took {total_time:.4f} seconds{RESET}") else: - print(f"⏱ Execution took {end - start:.4f} seconds") + print(f"⏱ Execution took {total_time:.4f} seconds") exit(level) @@ -68,7 +84,8 @@ class Timer: def print_result(self): elapsed = self.elapsed() if use_ANSI_Colors == True: - print(f"{self.name}: {WHITE}⏱ {elapsed:.6f} seconds{RESET}") + use_color = get_color_for_timer(elapsed) + print(f"{self.name}: {use_color}⏱ {elapsed:.6f} seconds{RESET}") else: print(f"{self.name}: ⏱ {elapsed:.6f} seconds") diff --git a/get_dups.sh b/get_dups.sh index ddc6b4f..7e4ba70 100755 --- a/get_dups.sh +++ b/get_dups.sh @@ -6,6 +6,8 @@ source myenv/bin/activate # Remove trailing slash path="${1%/}" +start_time=$(date +%s) + # Check if the first argument is a directory if [ ! -d "$path" ]; then echo "Error: '$path' is not a directory." @@ -75,3 +77,19 @@ for ((i = 0; i < ${#images[@]}; i++)); do done done + +end_time=$(date +%s) +elapsed=$((end_time - start_time)) + +# Convert to hours, minutes, seconds +hours=$((elapsed / 3600)) +minutes=$(( (elapsed % 3600) / 60 )) +seconds=$((elapsed % 60)) + +printf "Total time to dedup everything: %02d:%02d:%02d\n" $hours $minutes $seconds + +if [ "$2" != "forreal" ] && [ -f "dups.txt" ]; then + more dups.txt +else + echo "No Dups found" +fi