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)
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):
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:
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()
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(
+ """
<style>
body{background-color:#303030;}
div#time{color:#dddddd;}
div#date{color:#dddddd;}
</style>
-<center>""")
+<center>"""
+ )
if self.is_video[id]:
- f.write('<iframe src="%s" seamless width=%s height=%s></iframe>' % (self.photo_urls[id], self.width[id], self.height[id]))
+ f.write(
+ '<iframe src="%s" seamless width=%s height=%s></iframe>'
+ % (self.photo_urls[id], self.width[id], self.height[id])
+ )
else:
- f.write('<img src="%s" width=%s alt="%s">' % (self.photo_urls[id], self.width[id], self.photo_urls[id]))
+ f.write(
+ '<img src="%s" width=%s alt="%s">'
+ % (self.photo_urls[id], self.width[id], self.photo_urls[id])
+ )
f.write("</center>")
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()
-