7 class local_photos_mirror_renderer(renderer.debuggable_abstaining_renderer):
8 """A renderer that uses a local mirror of Google photos"""
10 album_root_directory = "/usr/local/export/www/gphotos/albums"
12 album_whitelist = sets.ImmutableSet([
13 '1208 Newer Alex Photos',
14 '1013 Scott and Lynn',
16 '1017 Olympic Sculpture Park',
18 '0730 Trip to East Coast \'16',
20 '1009 East Coast 2018',
21 '0819 Skiing with Alex',
23 '0227 Trip to California, \'16',
26 '0809 Bangkok and Phuket, 2003',
27 '0803 Blue Angels... Seafair',
34 '0407 Las Vegas, 2017',
37 extension_whitelist = sets.ImmutableSet([
45 def __init__(self, name_to_timeout_dict):
46 super(local_photos_mirror_renderer, self).__init__(name_to_timeout_dict, False)
47 self.candidate_photos = set()
49 def debug_prefix(self):
50 return "local_photos_mirror"
52 def periodic_render(self, key):
53 if (key == 'Index Photos'):
54 return self.index_photos()
55 elif (key == 'Choose Photo'):
56 return self.choose_photo()
58 raise error('Unexpected operation')
60 # Walk the filesystem looking for photos in whitelisted albums and
61 # keep their paths in memory.
62 def index_photos(self):
63 for root, subdirs, files in os.walk(self.album_root_directory):
64 last_dir = root.rsplit('/', 1)[1]
65 if last_dir in self.album_whitelist:
67 extension = x.rsplit('.', 1)[1]
68 if extension in self.extension_whitelist:
69 photo_path = os.path.join(root, x)
70 photo_url = photo_path.replace(
71 "/usr/local/export/www/",
74 self.candidate_photos.add(photo_url)
77 # Pick one of the cached URLs and build a page.
78 def choose_photo(self):
79 if len(self.candidate_photos) == 0:
82 path = random.sample(self.candidate_photos, 1)[0]
83 f = file_writer.file_writer('photo_23_none.html')
86 body{background-color:#303030;}
87 div#time{color:#dddddd;}
88 div#date{color:#dddddd;}
91 f.write('<img src="%s" style="display:block;max-width=800;max-height:600;width:auto;height:auto">' % path)
97 #x = local_photos_mirror_renderer({"Index Photos": (60 * 60 * 12),
98 # "Choose Photo": (1)})