6 from typing import Dict, Set
12 class local_photos_mirror_renderer(renderer.abstaining_renderer):
13 """A renderer that uses a local mirror of Google photos"""
15 album_root_directory = "/var/www/html/kiosk/images/gphotos/albums"
17 album_whitelist = frozenset(
20 "Bangkok and Phuket, 2003",
22 "Blue Angels... Seafair",
38 "Olympic Sculpture Park",
40 "Prague and Munich 2019",
47 "Trip to California, '16",
48 "Trip to San Francisco",
49 "Trip to East Coast '16",
58 extension_whitelist = frozenset(
68 def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
69 super().__init__(name_to_timeout_dict)
70 self.candidate_photos: Set[str] = set()
72 def debug_prefix(self) -> str:
73 return "local_photos_mirror"
75 def periodic_render(self, key: str) -> bool:
76 if key == "Index Photos":
77 return self.index_photos()
78 elif key == "Choose Photo":
79 return self.choose_photo()
81 raise Exception("Unexpected operation")
83 def album_is_in_whitelist(self, name: str) -> bool:
84 for wlalbum in self.album_whitelist:
85 if re.search("\d+ %s" % wlalbum, name) is not None:
89 def index_photos(self) -> bool:
90 """Walk the filesystem looking for photos in whitelisted albums and
91 keep their paths in memory.
93 for root, subdirs, files in os.walk(self.album_root_directory):
94 last_dir = root.rsplit("/", 1)[1]
95 if self.album_is_in_whitelist(last_dir):
96 for filename in files:
97 extension = filename.rsplit(".", 1)[1]
98 if extension in self.extension_whitelist:
99 photo_path = os.path.join(root, filename)
100 photo_url = photo_path.replace(
101 "/var/www/html", "http://kiosk.house/", 1
103 self.candidate_photos.add(photo_url)
106 def choose_photo(self):
107 """Pick one of the cached URLs and build a page."""
108 if len(self.candidate_photos) == 0:
111 path = random.sample(self.candidate_photos, 1)[0]
112 with file_writer.file_writer("photo_23_3600.html") as f:
116 body{background-color:#303030;}
117 div#time{color:#dddddd;}
118 div#date{color:#dddddd;}
123 f'<img src="{path}" style="display:block;max-width=800;max-height:600;width:auto;height:auto">'
130 # x = local_photos_mirror_renderer({"Index Photos": (60 * 60 * 12),
131 # "Choose Photo": (1)})