X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=inline;f=picasa_renderer.py;h=c3c45b757c2a8bb3ef9c8897bc6d9b29a68f60be;hb=8dc3a81f3bc8eb9ac4871b64c6d471493d293316;hp=d15bd7b1f88a6ae5500127c27ca47b44c5f6e6ed;hpb=4b1f3d8a8b278ca6d62f461ea80c8ea21080c301;p=kiosk.git diff --git a/picasa_renderer.py b/picasa_renderer.py index d15bd7b..c3c45b7 100644 --- a/picasa_renderer.py +++ b/picasa_renderer.py @@ -1,4 +1,4 @@ -import httplib +import http.client import gdata_oauth import file_writer import renderer @@ -8,49 +8,51 @@ import sets import random from oauth2client.client import AccessTokenRefreshError + class picasa_renderer(renderer.debuggable_abstaining_renderer): """A renderer to fetch photos from picasaweb.google.com""" - album_whitelist = sets.ImmutableSet([ - 'Alex', - 'Alex 6.0..8.0 years old', - 'Alex 3.0..4.0 years old', - 'Barn', - 'Bangkok and Phukey, 2003', - 'Blue Angels... Seafair', - 'Carol Ann and Owen', - 'Chahuly Glass', - 'Dunn Gardens', - 'East Coast, 2011', - 'East Coast, 2013', - 'Friends', - 'Gasches', - 'Gasch Wedding', - 'Hiking and Ohme Gardens', - 'Hiking', - 'Karen\'s Wedding', - 'Key West 2019', - 'Krakow 2009', - 'Munich, July 2018', - 'NJ 2015', - 'NW Trek', - 'Oahu 2010' - 'Ocean Shores 2009', - 'Ohme Gardens', - 'Olympic Sculpture Park', - 'Paintings', - 'Puerto Vallarta', - 'Photos from posts', - 'Random', - 'SFO 2014', - 'Soccer', - 'Skiing with Alex', - 'Tuscany 2008', - "Trip to California '16", - "Trip to East Coast '16", - 'Yosemite 2010', - 'Zoo', - ]) + album_whitelist = sets.ImmutableSet( + [ + "Alex", + "Alex 6.0..8.0 years old", + "Alex 3.0..4.0 years old", + "Barn", + "Bangkok and Phukey, 2003", + "Blue Angels... Seafair", + "Carol Ann and Owen", + "Chahuly Glass", + "Dunn Gardens", + "East Coast, 2011", + "East Coast, 2013", + "Friends", + "Gasches", + "Gasch Wedding", + "Hiking and Ohme Gardens", + "Hiking", + "Karen's Wedding", + "Key West 2019", + "Krakow 2009", + "Munich, July 2018", + "NJ 2015", + "NW Trek", + "Oahu 2010" "Ocean Shores 2009", + "Ohme Gardens", + "Olympic Sculpture Park", + "Paintings", + "Puerto Vallarta", + "Photos from posts", + "Random", + "SFO 2014", + "Soccer", + "Skiing with Alex", + "Tuscany 2008", + "Trip to California '16", + "Trip to East Coast '16", + "Yosemite 2010", + "Zoo", + ] + ) def __init__(self, name_to_timeout_dict, oauth): super(picasa_renderer, self).__init__(name_to_timeout_dict, False) @@ -64,12 +66,12 @@ class picasa_renderer(renderer.debuggable_abstaining_renderer): return "picasa" def periodic_render(self, key): - if (key == 'Fetch Photos'): + if key == "Fetch Photos": return self.fetch_photos() - elif (key == 'Shuffle Cached Photos'): + elif key == "Shuffle Cached Photos": return self.shuffle_cached() else: - raise error('Unexpected operation') + raise error("Unexpected operation") # Just fetch and cache the photo URLs in memory. def fetch_photos(self): @@ -78,25 +80,30 @@ class picasa_renderer(renderer.debuggable_abstaining_renderer): temp_width = {} temp_height = {} temp_is_video = {} - conn = httplib.HTTPSConnection("photoslibrary.googleapis.com") - conn.request("GET", - "/v1/albums", - None, - { "Authorization": "%s %s" % (self.oauth.token['token_type'], self.oauth.token['access_token']) - }) + conn = http.client.HTTPSConnection("photoslibrary.googleapis.com") + conn.request( + "GET", + "/v1/albums", + None, + { + "Authorization": "%s %s" + % (self.oauth.token["token_type"], self.oauth.token["access_token"]) + }, + ) response = conn.getresponse() if response.status != 200: - print("Failed to fetch albums, status %d\n" % response.status) - print response.read() + print(("Failed to fetch albums, status %d\n" % response.status)) + print(response.read()) albums = self.pws.GetUserFeed().entry for album in albums: - if (album.title.text not in picasa_renderer.album_whitelist): + if album.title.text not in picasa_renderer.album_whitelist: continue photos = self.pws.GetFeed( - '/data/feed/api/user/%s/albumid/%s?kind=photo&imgmax=1024u' % - (secrets.google_username, album.gphoto_id.text)) + "/data/feed/api/user/%s/albumid/%s?kind=photo&imgmax=1024u" + % (secrets.google_username, album.gphoto_id.text) + ) for photo in photos.entry: - id = '%s/%s' % (photo.albumid.text, photo.gphoto_id.text) + id = "%s/%s" % (photo.albumid.text, photo.gphoto_id.text) temp_is_video[id] = False resolution = 999999 for x in photo.media.content: @@ -118,9 +125,11 @@ class picasa_renderer(renderer.debuggable_abstaining_renderer): self.height = temp_height self.is_video = temp_is_video return True - except (gdata.service.RequestError, - gdata.photos.service.GooglePhotosException, - AccessTokenRefreshError): + except ( + gdata.service.RequestError, + gdata.photos.service.GooglePhotosException, + AccessTokenRefreshError, + ): print("******** TRYING TO REFRESH PHOTOS CLIENT *********") self.oauth.refresh_token() self.client = self.oauth.photos_service() @@ -134,36 +143,48 @@ class picasa_renderer(renderer.debuggable_abstaining_renderer): pid = random.sample(self.photo_urls, 1) id = pid[0] refresh = 15 - if (self.is_video[id]): refresh = 60 + if self.is_video[id]: + refresh = 60 - f = file_writer.file_writer('photo_23_none.html') - f.write(""" + f = file_writer.file_writer("photo_23_none.html") + f.write( + """ -