cleaning up options

This commit is contained in:
2024-12-12 11:17:55 -06:00
parent 354b299a90
commit 2f63fcb905

View File

@@ -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')