summaryrefslogtreecommitdiff
path: root/app/services/images.py
blob: f58b14467a421a972355a574b83fa991b4b484b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from pathlib import Path
from flask import Flask
import random

def get_all_images(current_app: Flask):
    images = []
    photos_dir = Path(f"{current_app.static_folder}/photos")
    for file_path in photos_dir.rglob("*"):
        if file_path.is_file():
            img_path = file_path.relative_to(current_app.static_folder)
            images.append(str(img_path))
    print(f"Returning {len(images)} images")
    shuffled = random.sample(list(images), k=len(images))
    return shuffled