Run:
python download-urls.py ./inaturalist.csv
The files will be in downloads/
import csv | |
import argparse | |
import os | |
from urllib.request import urlretrieve | |
def main(): | |
parser = argparse.ArgumentParser() | |
file_path = parser.add_argument("file") | |
args = parser.parse_args() | |
with open(args.file, "r") as f: | |
reader = csv.reader(f) | |
header_found = False | |
for row in reader: | |
if not header_found: | |
header_found = True | |
continue | |
print(row) | |
image_url = row[0] | |
image_file = "downloads/" + image_url.replace("/", "_") | |
if os.path.isfile(image_file): | |
print("Image skipped for {0}".format(line[0])) | |
else: | |
urlretrieve(image_url, filename=image_file) | |
print("Image saved at {0}".format(image_file)) | |
if __name__ == '__main__': | |
print("running") | |
main() |