X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=local_photos_mirror_renderer.py;h=2e5499dcc4a472559633ac88fc75aa64fdfbc0f2;hb=5e241dc47e497c547463cecc07946ea6882835a7;hp=0b8f7fc0a4b9e8724b8dc257e1df35724c121785;hpb=41262fc75551d35bcc9979011078b0e5b4e7b36a;p=kiosk.git diff --git a/local_photos_mirror_renderer.py b/local_photos_mirror_renderer.py index 0b8f7fc..2e5499d 100644 --- a/local_photos_mirror_renderer.py +++ b/local_photos_mirror_renderer.py @@ -4,53 +4,58 @@ import renderer import random import re + class local_photos_mirror_renderer(renderer.debuggable_abstaining_renderer): """A renderer that uses a local mirror of Google photos""" album_root_directory = "/usr/local/export/www/gphotos/albums" - album_whitelist = frozenset([ - '8-Mile Lake Hike', - 'Bangkok and Phuket, 2003', - 'Barn', - 'Blue Angels... Seafair', - 'Chihuly Glass', - 'Dunn Gardens', - 'East Coast 2018', - 'Fall \'17', - 'Friends', - 'Hiking', - 'Key West 2019', - 'Krakow 2009', - 'Kubota Gardens', - 'Las Vegas, 2017', - 'London, 2018', - 'Munich, July 2018', - 'NJ 2015', - 'Newer Alex Photos', - 'Ohme Gardens', - 'Olympic Sculpture Park', - 'Prague and Munich 2019', - 'Random', - 'Scott and Lynn', - 'SFO 2014', - 'Skiing with Alex', - 'Sonoma', - 'Trip to California, \'16', - 'Trip to San Francisco', - 'Trip to East Coast \'16', - 'Tuscany 2008', - 'Yosemite 2010', - 'Zoo', - ]) + album_whitelist = frozenset( + [ + "8-Mile Lake Hike", + "Bangkok and Phuket, 2003", + "Barn", + "Blue Angels... Seafair", + "Chihuly Glass", + "Dunn Gardens", + "East Coast 2018", + "Fall '17", + "Friends", + "Hiking", + "Key West 2019", + "Krakow 2009", + "Kubota Gardens", + "Las Vegas, 2017", + "London, 2018", + "Munich, July 2018", + "NJ 2015", + "Newer Alex Photos", + "Ohme Gardens", + "Olympic Sculpture Park", + "Prague and Munich 2019", + "Random", + "Scott and Lynn", + "SFO 2014", + "Skiing with Alex", + "Sonoma", + "Trip to California, '16", + "Trip to San Francisco", + "Trip to East Coast '16", + "Tuscany 2008", + "Yosemite 2010", + "Zoo", + ] + ) - extension_whitelist = frozenset([ - 'jpg', - 'gif', - 'JPG', - 'jpeg', - 'GIF', - ]) + extension_whitelist = frozenset( + [ + "jpg", + "gif", + "JPG", + "jpeg", + "GIF", + ] + ) def __init__(self, name_to_timeout_dict): super(local_photos_mirror_renderer, self).__init__(name_to_timeout_dict, False) @@ -60,16 +65,16 @@ class local_photos_mirror_renderer(renderer.debuggable_abstaining_renderer): return "local_photos_mirror" def periodic_render(self, key): - if (key == 'Index Photos'): + if key == "Index Photos": return self.index_photos() - elif (key == 'Choose Photo'): + elif key == "Choose Photo": return self.choose_photo() else: - raise error('Unexpected operation') + raise error("Unexpected operation") def album_is_in_whitelist(self, name): for wlalbum in self.album_whitelist: - if re.search('\d+ %s' % wlalbum, name) != None: + if re.search("\d+ %s" % wlalbum, name) != None: return True return False @@ -77,16 +82,15 @@ class local_photos_mirror_renderer(renderer.debuggable_abstaining_renderer): # keep their paths in memory. def index_photos(self): for root, subdirs, files in os.walk(self.album_root_directory): - last_dir = root.rsplit('/', 1)[1] + last_dir = root.rsplit("/", 1)[1] if self.album_is_in_whitelist(last_dir): for x in files: - extension = x.rsplit('.', 1)[1] + extension = x.rsplit(".", 1)[1] if extension in self.extension_whitelist: photo_path = os.path.join(root, x) photo_url = photo_path.replace( - "/usr/local/export/www/", - "http://10.0.0.18/", - 1) + "/usr/local/export/www/", "http://10.0.0.18/", 1 + ) self.candidate_photos.add(photo_url) return True @@ -96,21 +100,27 @@ class local_photos_mirror_renderer(renderer.debuggable_abstaining_renderer): print("No photos!") return False path = random.sample(self.candidate_photos, 1)[0] - f = file_writer.file_writer('photo_23_3600.html') - f.write(""" + f = file_writer.file_writer("photo_23_3600.html") + f.write( + """ -
""") - f.write('' % path) +
""" + ) + f.write( + '' + % path + ) f.write("
") f.close() return True + # Test code -#x = local_photos_mirror_renderer({"Index Photos": (60 * 60 * 12), +# x = local_photos_mirror_renderer({"Index Photos": (60 * 60 * 12), # "Choose Photo": (1)}) -#x.index_photos() -#x.choose_photo() +# x.index_photos() +# x.choose_photo()