0

I know it was a lot of similar question here.

I am trying to determine the best way to accomplish task:

  1. Download file with progress bar.
  2. 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.

Community
  • 1
  • 1
Andrei
  • 1,313
  • 4
  • 18
  • 35
  • There's no code here that will attempt to continue a failed download. What do you expect it to do? – byxor Dec 16 '16 at 13:25
  • `--continue` with `wget`. – Baris Demiray Dec 16 '16 at 13:25
  • 1
    @BrandonIbbotson yeah, I know it, sorry for misleading. I wrote it here to show my download algorithm without continuing to change it based on your answers or find the completed package which has already implemented this functionality above – Andrei Dec 16 '16 at 13:28
  • @BarisDemiray wow! I didn't find these args in wget [here](https://pypi.python.org/pypi/wget). The utility wget in Ubuntu and wget Python package is really the same thing? – Andrei Dec 16 '16 at 13:30
  • Nope, I thought you had meant the command line tool. That package does not seem to support continuation, see https://bitbucket.org/techtonik/python-wget/src/3001fd1b30aca7e5fe162c9193ccbb951dabb4ea/wget.py?at=default&fileviewer=file-view-default. – Baris Demiray Dec 16 '16 at 13:51

0 Answers0