summaryrefslogtreecommitdiff
path: root/app/services/images.py
blob: 3ce804519abec79ff9192cbec3e31137aa063158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pathlib import Path
import random

print(str(Path.cwd()))
root_dir = Path.cwd()
photos_dir = Path(f"{root_dir}photos")

image_cache = set()

def cache_images():
    for file_path in photos_dir.rglob("*"):
        if file_path.is_file():
            image_path = file_path.relative_to(root_dir).name
            image_cache.add(str(image_path))

def get_all_images():
    # if not image_cache:
    cache_images()
    print(f"returning {len(image_cache)} images")
    shuffled = random.sample(list(image_cache), k=len(image_cache))
    return shuffled