X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=picasa_renderer.py;fp=picasa_renderer.py;h=c3c45b757c2a8bb3ef9c8897bc6d9b29a68f60be;hb=5e241dc47e497c547463cecc07946ea6882835a7;hp=9de0c2d543acc7b617f1fc4e173cc8d837460a15;hpb=41262fc75551d35bcc9979011078b0e5b4e7b36a;p=kiosk.git diff --git a/picasa_renderer.py b/picasa_renderer.py index 9de0c2d..c3c45b7 100644 --- a/picasa_renderer.py +++ b/picasa_renderer.py @@ -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): @@ -79,24 +81,29 @@ class picasa_renderer(renderer.debuggable_abstaining_renderer): temp_height = {} temp_is_video = {} 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']) - }) + 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()) 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( + """ -
""") +
""" + ) if self.is_video[id]: - f.write('' % (self.photo_urls[id], self.width[id], self.height[id])) + f.write( + '' + % (self.photo_urls[id], self.width[id], self.height[id]) + ) else: - f.write('%s' % (self.photo_urls[id], self.width[id], self.photo_urls[id])) + f.write( + '%s' + % (self.photo_urls[id], self.width[id], self.photo_urls[id]) + ) f.write("
") f.close() return True + # Test code -oauth = gdata_oauth.OAuth(secrets.google_client_id, - secrets.google_client_secret) +oauth = gdata_oauth.OAuth(secrets.google_client_id, secrets.google_client_secret) oauth.get_new_token() if not oauth.has_token(): user_code = oauth.get_user_code() - print('------------------------------------------------------------') - print(('Go to %s and enter the code "%s" (no quotes, case-sensitive)' % ( - oauth.verification_url, user_code))) + print("------------------------------------------------------------") + print( + ( + 'Go to %s and enter the code "%s" (no quotes, case-sensitive)' + % (oauth.verification_url, user_code) + ) + ) oauth.get_new_token() -x = picasa_renderer({"Fetch Photos": (60 * 60 * 12), - "Shuffle Cached Photos": (1)}, - oauth) +x = picasa_renderer( + {"Fetch Photos": (60 * 60 * 12), "Shuffle Cached Photos": (1)}, oauth +) x.fetch_photos() -