test.py
1.03 KB
import qt
import requests
import time
#https://stackoverflow.com/questions/13909900/progress-of-python-requests-post
progress = qt.QProgressDialog(mainWindow())
link = "http://172.16.71.222:5000/uploads/G000639_2021-08-09_062219_result.nii.gz"
file_name = "download.data"
with open(file_name, "wb") as f:
print("Downloading %s" % file_name)
response = requests.get(link, stream=True)
total_length = response.headers.get('content-length')
if total_length is None: # no content length header
f.write(response.content)
else:
dl = 0
total_length = int(total_length)
print("Total len: ", total_length)
for data in response.iter_content(chunk_size=32):
dl += len(data)
f.write(data)
done = int(100.0 * dl / total_length)
print("Done: ", done, " ", type(data), " ", len(data))
progress.setValue(done)
time.sleep(0.1)
slicer.app.processEvents()
if dl >= total_length: break
progress.setValue(100)