-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh_slides.py
More file actions
50 lines (44 loc) · 1.29 KB
/
refresh_slides.py
File metadata and controls
50 lines (44 loc) · 1.29 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
'''
Scan directory and send result to redis (and so to web page thought websocket)
'''
import json
from pathlib import Path
from redis import Redis
import cv2
import settings
import os
WIDTH = 1024
HEIGHT = 716
DESTPATH = settings.SLIDES_PATH
def resize(f):
img = cv2.imread(f.as_posix())
h, w = img.shape[:2]
k = 1
if w > h:
k = WIDTH / w
else:
k = HEIGHT / h
h = int(h * k)
w = int(w * k)
img = cv2.resize(img, (w, h))
cv2.imwrite(os.path.join(DESTPATH, f.name.lower()), img)
def prepare_imgs(src_folder):
p = Path(src_folder)
for f in p.glob('**/*'):
if not f.name.lower().endswith('.jpg') and not f.name.lower().endswith('.jpeg'):
continue
if '.AppleDouble' in str(f):
continue
if os.path.exists(os.path.join(DESTPATH, f.name.lower())):
continue
print(str(f))
resize(f)
if __name__ == '__main__':
import sys
prepare_imgs(sys.argv[1] or './')
p = Path(settings.SLIDES_PATH)
redis = Redis()
imgs = [f.as_posix().replace(settings.SLIDES_PATH, '') for f in p.glob('*') if
f.is_file() and not f.name.startswith('.')]
print(f"Sending {len(imgs)} slides")
redis.publish('/ws/control', json.dumps({'action': 'refreshSlides', 'slides': imgs}))