Created
November 29, 2012 12:52
-
-
Save nucklearproject/4168861 to your computer and use it in GitHub Desktop.
Uploading images to picasa web with python and Gdata
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/python | |
# -*- coding: utf-8 -*- | |
### | |
# Este Script sube fotos a tu album de Picasa web. | |
# Uso : python uploader.py -l <directorio> | |
### | |
import gdata.photos.service | |
import gdata.media | |
import gdata.geo | |
import os | |
import dircache | |
import sys | |
import getopt | |
### | |
# Inicializamos | |
### | |
def init(path): | |
print 'Subiendo fotos a ', (path) | |
DIR_UPLOAD=path | |
gd_client = gdata.photos.service.PhotosService() | |
gd_client.email = 'ACCOUNTNAME' #tu nombre de usuario sin @gmail... | |
gd_client.password = 'SECRETPASS' #tu password | |
gd_client.source = 'python uploader' | |
gd_client.ProgrammaticLogin() | |
username=gd_client.email | |
index = 0 | |
albums = gd_client.GetUserFeed(user=username) | |
albumidlist = [] | |
# Listando y seleccionando unos de los album's disponbles en picasa | |
for album in albums.entry: | |
index = index + 1 | |
albumidlist.append(album.gphoto_id) | |
print '%d %s' %(index,album.title.text) | |
#Seleccionamos un album del listado (ingresar el numero de album) | |
choice = int(raw_input('Ingrese el número de album: ')) | |
album_url = '/data/feed/api/user/%s/albumid/%s' %(username, albumidlist[choice-1].text) | |
try: | |
pics_list = dircache.listdir(DIR_UPLOAD) | |
except: | |
print 'El directorio no es válido :( ' | |
usage() | |
count = 0 | |
#Subiendo las imágenes y a su vez elimnandolas una vez subidas | |
for pic in pics_list: | |
filename = DIR_UPLOAD+'/'+pic | |
try: | |
photo = gd_client.InsertPhotoSimple(album_url, pic, str(count)+'JPG', filename,content_type='image/jpeg') | |
count = count + 1 | |
os.remove(filename) | |
print count | |
except: | |
print 'No se pudo completar la operación, espere un momento...' | |
photos = gd_client.GetUserFeed(kind='photo', limit=count+1) | |
nombreGaleria = raw_input('Ingrese el nombre de la galeria :') | |
for photo in photos.entry: | |
#Recibiendo las imágenes y agregando el tag HML img | |
print '<img src="'+photo.content.src+'" title="'+nombreGaleria+'" alt="'+nombreGaleria+'" /><br />' | |
def usage(): | |
print 'python uploader.py -l <directorio> ' | |
exit(0) | |
if __name__=='__main__': | |
path = '' | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "l:v",["directory"]) | |
for option in opts: | |
if option[0] == '-l': | |
path = option[1] | |
except: | |
usage() | |
init(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment