From bc7ccc83e205a6e9073453fc02bb841af55c8873 Mon Sep 17 00:00:00 2001 From: lmluk Date: Sat, 7 Sep 2024 17:39:22 +0200 Subject: [PATCH] add status bar --- main.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 3739a99..ca31125 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,29 @@ def init_global_var(args: argparse.Namespace): def verbose_msg(msg: str): if verbose: print(msg) + +def printProgressBar (iteration: int, total: int, prefix: str='', suffix: str='', decimals: str=1, length: int=100, fill: str='█', printEnd: str="\r"): + """ + Call in a loop to create terminal progress bar + @params: + iteration - Required : current iteration (Int) + total - Required : total iterations (Int) + prefix - Optional : prefix string (Str) + suffix - Optional : suffix string (Str) + decimals - Optional : positive number of decimals in percent complete (Int) + length - Optional : character length of bar (Int) + fill - Optional : bar fill character (Str) + printEnd - Optional : end character (e.g. "\r", "\r\n") (Str) + """ + percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) + filledLength = int(length * iteration // total) + bar = fill * filledLength + '-' * (length - filledLength) + print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd) + # Print New Line on Complete + if iteration == total: + print() + + def get_img_filename(image: json): """ Returns the image filename from a image object (frontImage, backImage, primary, secondary) @@ -91,13 +114,20 @@ def apply_memory_on_imgs(memory: json, memory_dt: datetime): def export_images(memories: json): + memory_count = len(memories) - for i, n in zip(memories, range(len(memories))): + for i, n in zip(memories, range(memory_count)): memory_dt = get_datetime_from_str(i['takenTime']) + if time_span[0] <= memory_dt <= time_span[1]: verbose_msg("\nExport BeReal nr %s:" % n) apply_memory_on_imgs(i, memory_dt) + if verbose: + printProgressBar(n+1, memory_count, prefix="Exporting Images", suffix=("- Current Date: %s" % memory_dt.strftime("%Y-%m-%d")), printEnd='\n') + else: + printProgressBar(n+1, memory_count, prefix="Exporting Images") + if __name__ == '__main__':