File size: 2,588 Bytes
98ceb88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Download public-domain example images for all four demo apps.
Run once before first launch:  python scripts/fetch_examples.py
"""

import urllib.request
from pathlib import Path

EXAMPLES_DIR = Path(__file__).parent.parent / "examples"
EXAMPLES_DIR.mkdir(exist_ok=True)

# Each entry: (local_filename, url, description)
IMAGES = [
    # allergen_lens — food labels
    (
        "allergen_label.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/33/Nutrition_facts_label_example.jpg/640px-Nutrition_facts_label_example.jpg",
        "Nutrition facts label (allergen_lens example 1)",
    ),
    (
        "allergen_label2.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a3/Nutritional_labels.jpg/640px-Nutritional_labels.jpg",
        "Ingredient list label (allergen_lens example 2)",
    ),
    # camera_roll_concierge — varied everyday photos
    (
        "concierge_receipt.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Store_receipt.jpg/640px-Store_receipt.jpg",
        "Receipt photo (camera_roll example)",
    ),
    (
        "concierge_recipe.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat_03.jpg/640px-Cat_03.jpg",
        "Placeholder photo (camera_roll example)",
    ),
    # object_oracle — interesting objects
    (
        "oracle_object.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png",
        "Interesting object (oracle example)",
    ),
    # whats_that_error — error screens
    (
        "error_screen.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Windows_9X_BSOD.png/640px-Windows_9X_BSOD.png",
        "BSOD error screen (whats_that_error example 1)",
    ),
    (
        "error_screen2.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Windows_XP_BSOD.png/640px-Windows_XP_BSOD.png",
        "XP BSOD error screen (whats_that_error example 2)",
    ),
]


def fetch_all():
    for filename, url, desc in IMAGES:
        dest = EXAMPLES_DIR / filename
        if dest.exists():
            print(f"  skip  {filename}")
            continue
        print(f"  get   {filename}{desc}")
        try:
            urllib.request.urlretrieve(url, dest)
            print(f"  ok    {filename}")
        except Exception as exc:
            print(f"  FAIL  {filename}: {exc}")


if __name__ == "__main__":
    print(f"Downloading examples to {EXAMPLES_DIR} ...")
    fetch_all()
    print("Done.")