Skip to content

Instantly share code, notes, and snippets.

@Noah-Huppert
Created July 8, 2024 18:43
Show Gist options
  • Save Noah-Huppert/61b6d8fc3dae5f81e11fafad817ee6e8 to your computer and use it in GitHub Desktop.
Save Noah-Huppert/61b6d8fc3dae5f81e11fafad817ee6e8 to your computer and use it in GitHub Desktop.

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment