CoreyMSchafer/code_snippets

suggested edit to download-images.py

Opened this issue · 0 comments

I do not have a sign up for https://images.unsplash.com. So I change the url to github and wound up with one file.

from:

def download_image(img_url):
    img_bytes = requests.get(img_url).content
    img_name = img_url.split('/')[3] #<-------------------
    img_name = f'{img_name}.jpg' #<-------------------
    with open(img_name, 'wb') as img_file:
        img_file.write(img_bytes)
        print(f'{img_name} was downloaded...')

To:

def download_image(img_url):
    img_bytes = requests.get(img_url).content
    img_name = img_url.split('/')[-1] #<------------------
    #img_name = f'{img_name}.jpg' #<------------------
    with open(img_name, 'wb') as img_file:
        img_file.write(img_bytes)
        print(f'{img_name} was downloaded...')