-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-slideshow.py
More file actions
94 lines (72 loc) · 2.92 KB
/
update-slideshow.py
File metadata and controls
94 lines (72 loc) · 2.92 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
"""
Build script to update slideshow.js with images from the slideshow folder.
Run this script whenever you add or remove images from:
- Slideshow Images/cropped images for slideshow/
Usage: python3 update-slideshow.py
"""
import os
import re
# Configuration
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
SLIDESHOW_JS = os.path.join(BASE_PATH, "slideshow.js")
# Folder to scan for images (relative path)
IMAGE_FOLDERS = [
"Slideshow Images/cropped images for slideshow"
]
# Supported image extensions
IMAGE_EXTENSIONS = ('.jpeg', '.jpg', '.png', '.webp')
def get_images_from_folders():
"""Scan folders and return list of image paths."""
images = []
for folder in IMAGE_FOLDERS:
folder_path = os.path.join(BASE_PATH, folder)
if not os.path.exists(folder_path):
print(f"Warning: Folder not found: {folder}")
continue
for filename in sorted(os.listdir(folder_path)):
if filename.lower().endswith(IMAGE_EXTENSIONS):
# Skip non-VSCO versions if VSCO version exists
if not filename.endswith('-VSCO.jpeg') and filename.endswith('.JPG'):
vsco_version = filename.replace('.JPG', '-VSCO.jpeg')
if os.path.exists(os.path.join(folder_path, vsco_version)):
continue
image_path = f"{folder}/{filename}"
images.append(image_path)
return images
def generate_images_array(images):
"""Generate JavaScript array string for images."""
lines = ["// Slideshow data - dynamically generated by update-slideshow.py"]
lines.append("const slideshowImages = [")
for img in images:
lines.append(f' {{ src: "{img}", alt: "Fifth Flora floral arrangement" }},')
lines.append("];")
return "\n".join(lines)
def update_slideshow_js(new_array):
"""Update slideshow.js with new images array."""
with open(SLIDESHOW_JS, 'r') as f:
content = f.read()
# Pattern to match the existing slideshowImages array
pattern = r'// Slideshow data.*?const slideshowImages = \[[\s\S]*?\];'
if re.search(pattern, content):
new_content = re.sub(pattern, new_array, content)
else:
# Fallback: replace just the array
pattern = r'const slideshowImages = \[[\s\S]*?\];'
new_content = re.sub(pattern, new_array.split('\n', 1)[1], content)
with open(SLIDESHOW_JS, 'w') as f:
f.write(new_content)
def main():
print("Scanning image folders...")
images = get_images_from_folders()
print(f"Found {len(images)} images")
print("Generating slideshow array...")
new_array = generate_images_array(images)
print("Updating slideshow.js...")
update_slideshow_js(new_array)
print(f"Done! slideshow.js updated with {len(images)} images.")
print("\nImages included:")
for img in images:
print(f" - {img}")
if __name__ == "__main__":
main()