This script uploads the pics in the specified directory into the specified album in picasa. The script requires gdata libraries installed. Check
I had written and tested the code in linux platform. Hasn't been tested in windows.
Any suggestions to add more functionality, or add a UI or any improvements would be great.


# This script serves to upload the pictures from the specified directory to the specified album in picasa.
# Usage : python picasaUploader -l <source directory> 
import gdata.geo
import os
import dircache
import sys
import getopt

# Method that performs all initializations and insertions into the album
def init(path):
	print 'Uploading pics from path ', (path)
	gd_client = = 'jason.cosmo' #type your username here
	gd_client.password = os.environ['PASSWRD'] # store your password in an environment variable called PASSWD
	gd_client.source = 'python uploader'
	index = 0
	albums = gd_client.GetUserFeed(user=username)
	albumidlist = []
	# add each album in the list
	for album in albums.entry:
		index = index + 1
		print '%d %s' %(index,album.title.text)  

	#This choice would be the index of the album chosen from the list
	choice = int(raw_input('Choose the album you want to insert the pics in:'))
	album_url = '/data/feed/api/user/%s/albumid/%s' %(username, albumidlist[choice-1].text)

	#store the references to the pics in the
	#directory in the list
		pics_list = dircache.listdir(DIR_UPLOAD)
		print 'Enter a valid directory'		
	count = 0
	#upload the pics one by one
	for pic in pics_list:
		filename = DIR_UPLOAD+'/'+pic
			photo = gd_client.InsertPhotoSimple(album_url, pic, str(count)+'JPG', filename,content_type='image/jpeg')
			count = count + 1
			print count
			print 'Count not upload', Photo

# Method that shows the script usage
def usage():
	print 'Usage : python -l <directory path>'

if __name__=='__main__':
	path = ''
		opts, args = getopt.getopt(sys.argv[1:], "l:v",["directory"])
		for option in opts:
			if option[0] == '-l':
				path = option[1]				


Is it secure to store the password as an environment variable?

It sure isn't. But as the above script was written quickly and I thought it would be better to have it as an environment variable instead of putting it in the code, I couldn't think of a better alternative.
You are safe though, if you terminate the shell as soon as the program ends :)

This article has been dead for over six months. Start a new discussion instead.