2010-03-12

Sometimes Google is great

Last weekend we have been invited to a neighbour's 5th birthday party. It has taken place at a kids' entertainment park in a shopping centre. I took my camera, and the neighbours asked me to share the pictures.

So, I decided I want to post the pictures at PicasaWeb. It's web galleries are quite convenient and featureful, look like a good place to dump large amounts of photos someone wants you to share. Facebook, in contrast, scales them down to obscenely small sizes. Since I already have a Google account, I just had to click the Register button, and I got into my gallery with my Blogger avatar already in it. I created a new album, but the upload form for adding pictures was so 1990's. It had 5 file upload input fields. Even if new ones would appear as needed, it meant that I would have to select each and every photo individually.

I started looking for a tool for automatic upload into Picasa, but a stand-alone tool for that doesn't seem to exist in Ubuntu. There is, however, a python-gdata package with a Python API to Google online services. I googled "python gdata" and got the documentation in Google Code as the first hit. It has a section on PicasaWeb. 15 minutes later the photos were already on the way. Here is the script:

#!/usr/bin/env python
"""upicasa.py -- an upload script for PicasaWeb"""
import sys
import gdata.photos.service
import gdata.media
import gdata.geo

EMAIL = 'xxxx.xxxx@gmail.com'
PASSWORD = 'XXXXX'

def main():
gd_client = gdata.photos.service.PhotosService()
gd_client.email = EMAIL
gd_client.password = PASSWORD
gd_client.source = 'alga-upicasa-1'
print "Authenticating..."
gd_client.ProgrammaticLogin()

## I used this to fish out the album id pasted below
#albums = gd_client.GetUserFeed(user=EMAIL)
#for album in albums.entry:
# print 'title: %s, number of photos: %s, id: %s' % (album.title.text,
# album.numphotos.text,
# album.gphoto_id.text)
#return

album_id = '123123123123132123'
album_url = '/data/feed/api/user/%s/albumid/%s' % (EMAIL, album_id)
for photo in sys.argv[1:]:
print "uploading", photo
photo = gd_client.InsertPhotoSimple(album_url, 'New Photo',
'', # title
photo, content_type='image/jpeg')


if __name__ == '__main__':
main()

It was really fun and empowering to get the photos programmatically uploading into online albums in such a short time. Top marks to Google for providing this simple, sensible way to manage data on Google. No app registration, no developer keys, no nonsense, just the Google login and password are needed to get started. I think I'll develop this script a bit to allow for managing the albums from command line and uploading photos into them, then add it to Python Package Index. Perhaps a simple GUI could also be useful.

3 comments:

Andrey Lebedev said...

Actually, simple (well, ok, "simple") GUI is already available for some time.

Binary only and quite resource-hungry though.

Paul Carduner said...

Have you tried http://divvyshot.com? It lets everyone else who went to the party upload their high resolution photos to the same place. Then everyone can download a zip file with all the photos. No need for uploader scripts either.

It's written in Python too :)

Albertas Agejevas said...

Paul, I'll try it out, thanks.

The divvyshot front page has a weird design/usability bug: on my 1024x768 laptop screen the navigation bar is just above the fold, and clicking on the navlinks gives a perfect impression of a broken menu, as only things below the fold change. It took me some time to figure out what was going on.