def get_albums(): pws = PhotosService() uf = pws.GetUserFeed(user=settings.PICASAGALLERY_USER) feed = '{uri}&thumbsize={thumbsize}'.format(uri=uf.GetAlbumsUri(), thumbsize=ALBUM_THUMBSIZE) print feed return pws.GetFeed(feed).entry
def logon_to_picasaweb(): gd_client = PhotosService() gd_client.email = USER gd_client.password = PASSWORD gd_client.source = 'kokorice.importer' gd_client.ProgrammaticLogin() return gd_client
def __init__(self, email, client_secret, credentials_dat): self._storage = Storage(credentials_dat) self._credentials = self._storage.get() if self._credentials is None or self._credentials.invalid: flow = flow_from_clientsecrets(client_secret, scope=PICASA_OAUTH_SCOPE, redirect_uri=PICASA_REDIRECT_URI) uri = flow.step1_get_authorize_url() print 'open to browser:' print uri code = raw_input('Enter the authentication code: ').strip() self._credentials = flow.step2_exchange(code) client = PhotosService() client.email = email client.source = 'inter-chat-bridge' self.client = client self.albums = {} self._refresh_auth_token()
def login(email): if not os.path.exists(CONFIG_PATH): os.makedirs(CONFIG_PATH) if not os.path.exists(CLIENT_SECRETS): _generate_client_secrets() credentials = _load_credentials(email) additional_headers = { "Authorization": "Bearer %s" % credentials.access_token } gd_client = PhotosService(source=USER_AGENT, email=email, additional_headers=additional_headers) return gd_client
def get_albums(): data = [] album_entries = PhotosService().GetUserFeed(user=settings.PP_USERID).entry for entry in album_entries: if entry.name.text in settings.PP_IGNORED_ALBUMS: continue thumb = entry.media.thumbnail[SMALL_THUMB] album = Album() album.id = entry.GetAlbumId() album.name = entry.name.text album.title = entry.title.text album.numphotos = entry.numphotos.text album.updated = entry.updated.text album.cover_url = thumb.url album.cover_width = int(thumb.width) album.cover_height = int(thumb.height) album.photos_feed_uri = entry.GetPhotosUri() data.append((album.name, album)) return data
def get_photos(album_name, photos_feed_uri): data = [] photo_entries = PhotosService().GetFeed(photos_feed_uri).entry for i, entry in enumerate(photo_entries): thumb = entry.media.thumbnail[MID_THUMB] sized_url = entry.content.src.rsplit("/", 1) sized_url.insert(-1, "s640") photo = Photo() photo.id = entry.gphoto_id.text photo.pos = i + 1 photo.caption = entry.summary.text or '' photo.url = "/".join(sized_url) photo.size = int(entry.size.text) photo.width = int(entry.width.text) photo.height = int(entry.height.text) photo.thumb_url = thumb.url photo.thumb_width = int(thumb.width) photo.thumb_height = int(thumb.height) photo.album_name = album_name data.append((photo.id, photo)) return data
def __init__(self, config): """Constructor.""" PhotosService.__init__(self) googlecl.service.BaseServiceCL.__init__(self, googlecl.picasa.SECTION_HEADER, config)
def get_photos(album): feed = '{uri}&imgmax={imgmax}&thumbsize={thumbsize}'.format( uri=album.GetPhotosUri(), imgmax=PHOTO_IMGMAXSIZE, thumbsize=PHOTO_THUMBSIZE) return PhotosService().GetFeed(feed).entry
__all__ = ['PicasaContainer'] from gdata.photos.service import PhotosService, GooglePhotosException from peewee.debug import GET_LOGGER, PRINT_EXCEPTION from peewee.misc_utils import MetaSingleton from pygui.item.containers import GenericContainer from pygui.item.core import ActionItem from pygui.item.mediaitem.core import ImageItem, MediaItem from pygui.window import MessageWindow, LoadingWindow, KeyboardWindow from pygui.facilities.picasa_config import PicasaConfig log = GET_LOGGER(__name__) # Init the Picasa Gdata client PicasaGData = PhotosService() PicasaGData.source = 'api-sample-google-com' # Picasa Generic Album # Provide access to Picasa album content # Param: # username: Picassa user when looking for public albums or 'default' when looking for private albums # gphoto_id: album_id class PicasaAlbumContainer(ImageItem, MediaItem, GenericContainer): def __init__(self, name, username, gphoto_id, parent=None, **kw): ImageItem.__init__(self, name, type_='image', **kw) MediaItem.__init__(self, name, type_='playlist', **kw) self.username = username self.gphoto_id = gphoto_id self.parent = parent
def picasa_sync(user, thumbsizes, imgmax): print 'Adding new albums:' gd_client = PhotosService() feed_url = '/data/feed/api/user/%s' % user feed_url += '?kind=album&thumbsize=%s' % ','.join(thumbsizes) feed = gd_client.GetFeed(feed_url) for entry in feed.entry: try: a = Album.objects.get(albumid=entry.gphoto_id.text) print 'Album %s already exists' % (a.title) except: published = datetime.strptime(entry.published.text[:-5], '%Y-%m-%dT%H:%M:%S') a = Album.objects.create(title=entry.title.text, name=entry.name.text, published=published, link=entry.link[1].href, albumid=entry.gphoto_id.text, summary=entry.summary.text) for thumb in entry.media.thumbnail: try: t = Thumbnail.objects.get(url=thumb.url) except: t = Thumbnail.objects.create(url=thumb.url, height=thumb.height, width=thumb.width) a.thumbnails.add(t) a.save() print 'Saved -', a.title print 'Adding new photos:' for album in Album.objects.all(): feed_url = '/data/feed/api/user/%s/album/%s' % (user, str(album.name)) feed_url += '?kind=photo&thumbsize=%s' % ','.join(thumbsizes) feed_url += '&imgmax=%s' % imgmax feed = gd_client.GetFeed(feed_url) for entry in feed.entry: try: p = Photo.objects.get(photoid=entry.gphoto_id.text) print 'Photo %s already exists' % (p.title) except: published = datetime.strptime(entry.published.text[:-5], '%Y-%m-%dT%H:%M:%S') a = Album.objects.get(albumid=entry.albumid.text) p = Photo.objects.create(title=entry.title.text, published=published, link=entry.link[1].href, photoid=entry.gphoto_id.text, summary=entry.summary.text, album=a) for thumb in entry.media.thumbnail: try: t = Thumbnail.objects.get(url=thumb.url) except: t = Thumbnail.objects.create(url=thumb.url, height=thumb.height, width=thumb.width) p.thumbnails.add(t) content = entry.media.content[0] try: c = Content.objects.get(url=content.url) except: c = Content.objects.create(url=content.url, height=content.height, width=content.width) p.content.add(c) p.save() print 'Saved -', p.title
def refresh_creds(self, credentials, sleep): global gd_client time.sleep(sleep) credentials.refresh(httplib2.Http()) now = datetime.utcnow() expires = credentials.token_expiry expires_seconds = (expires - now).seconds # print ("Expires %s from %s = %s" % (expires,now,expires_seconds) ) if self.service == 'docs': gd_client = DocsService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'picasa': gd_client = PhotosService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'finance': gd_client = FinanceService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'calendar': gd_client = CalendarService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'contacts': gd_client = ContactsService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'youtube': gd_client = YouTubeService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) elif self.service == 'blogger': gd_client = BloggerService(email='default', additional_headers={ 'Authorization': 'Bearer %s' % credentials.access_token }) d = threading.Thread(name='refresh_creds', target=self.refresh_creds, args=(credentials, expires_seconds - 10)) d.setDaemon(True) d.start() return gd_client