-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
57 lines (44 loc) · 1.53 KB
/
build.py
File metadata and controls
57 lines (44 loc) · 1.53 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
import os
import hashlib
import shutil
import json
from pathlib import Path
INPUT_DIR = Path('stickers')
OUTPUT_DIR = Path('dist')
MANIFEST_FILE = OUTPUT_DIR / 'stickers.json'
def get_file_hash(filepath):
"""Generate SHA-256 hash to detect duplicate stickers."""
hasher = hashlib.sha256()
with open(filepath, 'rb') as f:
buf = f.read()
hasher.update(buf)
return hasher.hexdigest()
def process_stickers():
OUTPUT_DIR.mkdir(exist_ok=True)
seen_hashes = set()
manifest = []
counter = 1
print("Initiating build pipeline...")
for file_path in INPUT_DIR.glob('*.webp'):
file_hash = get_file_hash(file_path)
# Deduplication check
if file_hash in seen_hashes:
print(f"Duplicate detected and destroyed: {file_path.name}")
continue
seen_hashes.add(file_hash)
# Rename and move to deployment folder
new_filename = f"sticker_{counter:03d}.webp"
output_path = OUTPUT_DIR / new_filename
shutil.copy2(file_path, output_path)
# Add to manifest
manifest.append({
"id": counter,
"src": new_filename
})
counter += 1
# Generate the JSON manifest
with open(MANIFEST_FILE, 'w') as f:
json.dump(manifest, f, indent=4)
print(f"Pipeline complete. {len(manifest)} unique stickers processed and staged in /dist.")
if __name__ == '__main__':
process_stickers()