diff options
| author | Dylan Bolger <dylan.bolger00@gmail.com> | 2026-08-17 16:58:04 -0500 |
|---|---|---|
| committer | Dylan Bolger <dylan.bolger00@gmail.com> | 2026-08-17 16:58:04 -0500 |
| commit | a06a7e8f23bfd64565da4e4141f186180e84a104 (patch) | |
| tree | 297a4fb79bccdb94cda9eaccecc4af9cc9766210 /app/services/images.py | |
| download | photoblog-a06a7e8f23bfd64565da4e4141f186180e84a104.tar.xz photoblog-a06a7e8f23bfd64565da4e4141f186180e84a104.zip | |
initial push of photoblog
Diffstat (limited to 'app/services/images.py')
| -rw-r--r-- | app/services/images.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/services/images.py b/app/services/images.py new file mode 100644 index 0000000..bd02384 --- /dev/null +++ b/app/services/images.py @@ -0,0 +1,20 @@ +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() + shuffled = random.sample(list(image_cache), k=len(image_cache)) + return shuffled |
