You are not logged in.

#1 2010-06-02 00:21:30

GogglesGuy
Member
From: Rocket City
Registered: 2005-03-29
Posts: 610
Website

Picasa Upload

I was looking for an easy to use script that could upload a bunch of photos to an album on picasa. I found one that could upload 1 at a time, but that wasn't really handy if you have  a whole bunch photos in a folder. So I created a script from scratch that allows you to easily do that:

./picasa_upload.py *.JPG
#!/usr/bin/env python

import gdata.photos.service
import getpass
import sys
import os.path
from optparse import OptionParser

def main():
  parser = OptionParser(usage="usage: %prog [options] images...", version="%prog v0.1.0")
  parser.add_option("-t", "--title", dest="title", default="New Album", help="Set the album title")
  parser.add_option("-s", "--summary", dest="summary", default="", help="Set the album summary")

  (options, args) = parser.parse_args()
  if len(args) == 0:
    parser.error("Please specify at least one photo.")

  # Get Credentials
  print 'Please enter your Google Account information'
  email    = raw_input('Email: ')
  password = getpass.getpass()

  # Create Service
  picasa = gdata.photos.service.PhotosService(email=email,password=password)

  # Try logging in
  try:
    picasa.ProgrammaticLogin()
  except gdata.service.CaptchaRequired:
      sys.exit('Google required a captcha.')
  except gdata.service.BadAuthentication:
      sys.exit('Bad Authentication')
  except gdata_client.Error:
      sys.exit('Login Error')

  # Create Album
  print 'Creating Album: %s ' % options.title
  try:
    album = picasa.InsertAlbum(title=options.title, summary=options.summary,access='private')
  except GooglePhotosException as gpe:
    sys.exit(gpe.message)

  # Upload Photos
  try:
    album_url = '/data/feed/api/user/default/albumid/%s' % (album.gphoto_id.text)
    for a in args:
      filename  = os.path.abspath(a)
      extension = os.path.splitext(filename)[1].lower()
      if extension=='.jpg' or extension=='.jpeg':
        print 'Uploading %s' % filename
        photo = picasa.InsertPhotoSimple(album_url,'New Photo','',filename,content_type='image/jpeg')
      else:
        print 'Skippin %s' % filename

  except GooglePhotosException as gpe:
    sys.exit(gpe.message)

if __name__ == "__main__":
    main()

Perhaps some real python programmers can extend it and make it more robust since this one doesn't check any errors or removes the newly created album if nothing was uploaded.

Added it in AUR as well: http://aur.archlinux.org/packages.php?ID=37757

Last edited by GogglesGuy (2010-06-02 13:42:07)

Offline

#2 2010-07-07 04:43:22

gdw
Member
Registered: 2008-05-24
Posts: 7

Re: Picasa Upload

Did you know that google just released the following?:

http://code.google.com/p/googlecl/

Offline

Board footer

Powered by FluxBB