-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_gifs.py
More file actions
27 lines (19 loc) · 769 Bytes
/
Copy pathmerge_gifs.py
File metadata and controls
27 lines (19 loc) · 769 Bytes
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
import random
from pathlib import Path
public_path = Path(__file__).parent / "public"
gifs_path = public_path / "88x31"
gifs = list(gifs_path.glob("*.gif"))
random.shuffle(gifs)
gifs_data = bytearray()
gif_html_elements = []
for i, gif in enumerate(gifs):
print("\rProcessed", i, "gifs...", end="")
gif_bytes = gif.read_bytes()
gifs_data += gif_bytes
gif_html_elements.append(
f'<img src="" alt="{gif.stem}" height="31" width="88" data-length="{len(gif_bytes)}" loading="lazy" />'
)
html_template = (public_path / "template.html").read_text()
index_html = html_template.replace("INSERT_GIF_ELEMENTS", "\n".join(gif_html_elements))
(public_path / "gif.data").write_bytes(gifs_data)
(public_path / "index.html").write_text(index_html)