|
GDataPhotos
Using the gdata.photos python module in your project.
(C) 2007 HÃ¥vard Gulldahl <havard@gulldahl.no> Portions copyright 2007 Google Inc. DEPRECATEDAs of 2007-12-22, the module documented here became a part of the official gdata module from Google. The new home for development and documentation is over there. This page is retained for historical reasons. IntroductionGoogle has done a tremendous job of making its remote apis accessible on python, through their gdata-python-client project. They have not, however, made something specifically for PicasaWeb, so I had to do it. Aboutgdata.photos provides a human-friendly interface to Google Photos (a.k.a Picasa Web) services. It extends gdata.service.GDataService and as such hides all the nasty details about authenticating, parsing and communicating with Google Photos. The module is heavily modelled after the existing, official Google GData modules. DownloadDownload the module from the download pages, or get it from svn: svn checkout http://picasapush.googlecode.com/svn/trunk/picasaweb photos You may also take a look at it online. DocumentationThe module's documentation (updated periodically) lives at http://picasapush.googlepages.com/index.html. Exampleimport gdata.photos, gdata.photos.service pws = gdata.photos.service.PhotosService() pws.ClientLogin(username, password) #Get all albums userfeed_albums = pws.GetUserFeed(kind='album') #Print some nice info about yourself print "User %s has these albums: %s" % (userfeed_albums.user.text, [a.title.text for a in userfeed_albums.entry]) print "%s is spending %sb on storage" % \ (userfeed_albums.nickname.text, userfeed_albums.quotacurrent.text) # Get all photos in the second album albumfeed_photos = pws.GetFeed(userfeed_albums.entry[1].GetPhotosUri()) # Get all tags for photos in second album and print them photofeed_tags = pws.GetFeed(userfeed_albums.entry[1].GetTagsUri()) print [ tag.summary.text for tag in photofeed_tags.entry ] # Get all comments for the first photos in list and print them photofeed_comments = pws.GetFeed(albumfeed_photos.entry[0].GetCommentsUri()) print [ c.summary.text for c in photofeed_comments.entry ] # Get a photo to work with photo = albumfeed_photos.entry[0] # Update metadata # Attributes from the <gphoto:*> namespace photo.summary.text = u'A nice view from my veranda' photo.title.text = u'Verandaview.jpg' # Attributes from the <media:*> namespace photo.media.keywords.text = u'Home, Long-exposure, Sunset' # Comma-separated # Adding attributes to media object photo.rotation = gdata.photos.Rotation(text='90') # Rotate 90 degrees clockwise # Submit modified photo object photo = pws.UpdatePhotoMetadata(photo) # Make sure you only modify the newly returned object, else you'll get versioning # errors. See Optimistic-concurrency # Add comment to a picture comment = pws.InsertComment(photo, u'I wish the water always was this warm') # Remove comment because it was silly print "*blush*" pws.Delete(comment) ~ Further reading |
Sign in to add a comment