Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to automate uploading image directories to picasa albums
#!/usr/bin/env python
import ConfigParser
import os
import os.path as op
import gdata.photos.service
import gdata.media
import gdata.geo
def upload_one_dir(gd_client, username, directory, files):
_,basedir = op.split(directory)
parts = [s.capitalize() for s in basedir.split('-')]
date = '-'.join(parts[:3])
slug = ' '.join(parts[3:])
title = date + ': ' + slug
album = gd_client.InsertAlbum(title=title, summary=date)
album_url = '/data/feed/api/user/%s/albumid/%s' % (username, album.gphoto_id.text)
for pic in files:
filename = op.join(directory, pic)
photo = gd_client.InsertPhotoSimple(album_url,
pic,
'',
filename,
content_type='image/jpeg')
print 'Uploaded', photo
def main(blogdir):
config = ConfigParser.RawConfigParser()
config.read('config.ini')
email = config.get('login', 'email')
username = config.get('login', 'username')
passwd = config.get('login', 'password')
# log in..
gd_client = gdata.photos.service.PhotosService()
gd_client.email = email
gd_client.password = passwd
gd_client.source = 'Blog pics uploader'
gd_client.ProgrammaticLogin()
for root, dirs, files in os.walk(blogdir):
if not files:
continue
print root
upload_one_dir(gd_client, username, root, files)
if __name__ == '__main__':
import sys
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment