From 2f63fcb9053bb3b589e672671a07612312e045e1 Mon Sep 17 00:00:00 2001 From: Steven Crawford Date: Thu, 12 Dec 2024 11:17:55 -0600 Subject: [PATCH] cleaning up options --- split_zip_into_under_5GB_chunks.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/split_zip_into_under_5GB_chunks.py b/split_zip_into_under_5GB_chunks.py index 8300142..2d31f05 100755 --- a/split_zip_into_under_5GB_chunks.py +++ b/split_zip_into_under_5GB_chunks.py @@ -3,6 +3,28 @@ import zipfile import os from io import BytesIO +def printProgressBar(iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\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_zip_path(): while True: zip_path = input("Enter the path to the zipped file: ") @@ -20,16 +42,23 @@ def split_zip(input_zip_path, output_folder, max_group_size=4.5 * 1024 * 1024 * with zipfile.ZipFile(input_zip_path, 'r') as source_zip: members = source_zip.namelist() + l = len(members) group_size = 0 group_number = 1 + i = 1 + printProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 100) for member in members: + i = i + 1 + printProgressBar(i, l, prefix = 'Progress:', suffix = 'Complete', length = 100) # Read the file content from the zip archive with BytesIO(source_zip.read(member)) as file_content: # Check if adding this file would exceed the maximum group size if (group_size + len(file_content.getvalue())) > max_group_size: + print(f'{file_name}-group_{group_number}.zip done.', end="\r") group_number += 1 group_size = 0 + # i = 0 output_zip_path = os.path.join(output_folder, f'{file_name}-group_{group_number}.zip')