def run(): images = list(Image.objects.all()) progress = Progress(len(images), 100) progress.draw() for img in images: url = BASE_URL + img.file.url path = img.file.url[1:] # Remove leading '/' try: os.makedirs(os.path.dirname(path)) except OSError as e: if e.errno != 17: raise e try: urllib.urlretrieve(url, path) except urllib.ContentTooShortError: print "Couldn't download", path progress.tick() print '\nDone'
def run(): image_urls = list(Image.objects.values_list('file', flat=True)) progress = Progress(len(image_urls), 100) progress.draw() for path in image_urls: url = BASE_URL + '/' + path try: os.makedirs(os.path.dirname(path)) except OSError as e: if e.errno != 17: raise e try: urllib.urlretrieve(url, path) except urllib.ContentTooShortError: print "Couldn't download", path progress.tick() print '\nDone'