

def scrape(iterator, location, limit):
    '\n    Downloads up to the limit of all photos in an iterator.\n    '
    for photo in iterator:
        filepath = '{0}/{1}/{2}.jpg'.format(location, (photo.flickrid % 100), photo.flickrid)
        if os.path.exists(filepath):
            log.info('Skipping duplicate {0}'.format(photo.flickrid))
            continue
        try:
            log.info('Downloading {0} ({1})'.format(photo.flickrid, photo.format))
            image = photo.download()
            try:
                image.save(filepath)
            except IOError:
                os.makedirs(os.path.dirname(filepath))
                image.save(filepath)
        except KeyboardInterrupt:
            raise
        except:
            pass
        limit -= 1
        if (limit == 0):
            break

dataset/ETHPy150Open cvondrick/pyvision/vision/flickr.py scrape/original