Source

emacs-blogger / picasa.py

Full commit
import gdata.photos.service
import gdata.media
import os
import mimetypes

class Client(object):
    
    def __init__(self):
        self.service = gdata.photos.service.PhotosService()

    def login(self, email, password):
        client = self.service
        client.email = email
        client.password = password
        client.source = "emacs-blogger"
        client.ProgrammaticLogin()

    def get_blogger_album(self):
        albums = self.service.GetUserFeed()
        balbum = None
        for album in albums.entry:
            if album.title.text=="Blogger":
                balbum = album
        
        if balbum:
            return balbum
        else:
            return self.service.InsertAlbum(title="Blogger", 
                                            summary="uploaded photos from the blog")

    def get_album_url(self, album):
        return "/data/feed/api/user/%s/albumid/%s" % (self.service.email,
                                                      album.gphoto_id.text)

    def add_photo(self, filename):
        album = self.get_blogger_album()
        album_url = self.get_album_url(album)
        
        photo_title = os.path.basename(filename)
        photo = self.service.InsertPhotoSimple(album_url, photo_title,
                                               "Photo uploaded for blogger use",
                                               filename,
                                               content_type=mimetypes.guess_type(filename)[0])
        return photo.content.src