Skip to content

Chap 1: lorempixel not working #3

@GabrielLins64

Description

@GabrielLins64

Lorempixel's endpoint seems out. Here's a functional code for sequential download:

import urllib.request
from os import mkdir
import time

SAVEPATH        = "tmp/"
URL             = "https://picsum.photos/200/300"
NUM_OF_IMAGES   = 4

try:
    mkdir(SAVEPATH)
except:
    pass

def download_img(img_path, filename):
    print("Downloading image from ", img_path)
    urllib.request.urlretrieve(img_path, filename)

def main():
    t0 = time.time()
    for i in range(NUM_OF_IMAGES):
        img_name = SAVEPATH + "image-" + str(i) + ".jpg"
        download_img(URL, img_name)
    
    total_time = time.time() - t0
    print(f"Total execution time: {total_time}")

if __name__ == '__main__':
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions