Created
October 29, 2010 13:29
-
-
Save atr000/653555 to your computer and use it in GitHub Desktop.
python cli util to upload images to picasa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
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() | |
Choose download location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment