I have a small script which reads data inside a file in chunks, encodes them and then runs curl to send a POST request for every chunk.
I would like to add a progress bar of the global upload status everytime the POST returns a '200 OK' instead of the upload status of every chunk
....
CHUNK_SIZE = 500
with open(file, "rb") as f:
while True:
chunk = (base64.b64encode(f.read(CHUNK_SIZE))).decode('ascii')
if not chunk:
print ("\n\n\n####COMPLETED####\n\n\n")
break
time.sleep(5)
...
upload part
...
if len(out) > 0:
if (str(out, 'utf-8').find("200 OK") != -1):
print ("\n\n\n####OK####\n\n\n")
else:
....
So, for example, if a file has a size of 2000 bytes and the chunks are set to 500 bytes, for every chunk sent, this is the output I would like to have ( right now I just get an "ok" ) but I could not get:
chunk 1:
"25% done"
chunk 2:
"50% done"
chunk 3:
"75% done"
chunk 4:
"100% - completed"
EDIT:
total = os.path.getsize(file)
num_chunks_uploaded = 0
max_chunks_tosend = total // CHUNK_SIZE
....
if len(out) > 0:
if (str(out, 'utf-8').find("200 OK") != -1):
print ("\n\n\n####OK####\n\n\n")
if ( num_chunks_uploaded <= max_chunks_tosend ):
num_chunks_uploaded += 1
#print(num_chunks_uploaded)
print(int(num_chunks_uploaded * CHUNK_SIZE / total * 100))