-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_testdata.py
More file actions
executable file
·46 lines (33 loc) · 1.18 KB
/
setup_testdata.py
File metadata and controls
executable file
·46 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import os
import sys
import urllib.request
from pathlib import Path
import time
TESTDATA_DIR = "testdata/images"
def download_images(num_images=50):
"""Download test images of various sizes"""
Path(TESTDATA_DIR).mkdir(parents=True, exist_ok=True)
print(f"Downloading {num_images} images from Lorem Picsum...")
print()
for i in range(1, num_images + 1):
if i % 3 == 0:
width, height = 400, 300
elif i % 3 == 1:
width, height = 800, 600
else:
width, height = 1920, 1080
url = f"https://picsum.photos/{width}/{height}?random={i}"
output_path = os.path.join(TESTDATA_DIR, f"test_image_{i}.jpg")
try:
print(f"Downloading image {i}/{num_images} ({width}x{height})...", end=" ")
urllib.request.urlretrieve(url, output_path)
time.sleep(0.1)
except Exception as e:
print(f"Failed to download image: {e}")
print()
print("Setup complete!")
print(f"Downloaded images to: {TESTDATA_DIR}")
if __name__ == "__main__":
num_images = int(sys.argv[1]) if len(sys.argv) > 1 else 50
download_images(num_images)