I know it was a lot of similar question here.
I am trying to determine the best way to accomplish task:
- Download file with progress bar.
- If my script has been completed incorrectly, after restarting script, it continued to download a file and not downloaded again (it's necessary for large files).
My code, using tqdm and request, base on this question:
def download(url, dest):
logger.info('Downloading {0}'.format(url))
r = requests.get(url, stream=True)
download_size = int(r.headers.get('content-length'))
logger.debug('Download size: {0}'.format(download_size))
with open(dest, 'wb') as f:
for chunk in tqdm(r.iter_content(chunk_size=1024), total=int((download_size / 1024) + 1)):
if chunk:
f.write(chunk)
f.flush()
logger.info('File {0} downloaded.'.format(dest))
return True
This code doesn't continue to download file in a restart.
I was looking for a complete package in PyPi, but I couldn't find anyhing. Maybe I overlooked something?
P.S. I think wget can help, but haven't found how there continue downloading.