Script para subir fotos a flickr

 

#!/usr/bin/env python


# Basado en sendmsg.py de follower@myrealbox.com
# Author: Javier Santana qualopec@gmail.com

#
# License: GPL 2.0
#


import os
import sys
import logging
import libgmail
from  glob import glob;
import pickle;
from os.path import basename;

path_to_shots = "C:\\path\\a\\tus\\shots"
mail_to = "tu_correo_flickr@photos.flickr.com";
extensions = ["jpg","png"];

settings_file = "settings.dat"

account_user = "tu_correo@gmail.com"
account_pass = "tu_pass"

def load_sent_files():

    #leer el fichero si existe
    try:
        f = open(settings_file,'rb')
    except:
        sent_files = [];
    else:
        sent_files = pickle.load(f)
        
    return sent_files;
    
def save_new_files(new_files):

    pickle.dump(new_files + load_sent_files(),open(settings_file,"wb"));
    
def get_new_files():
    files = [];
    for x in extensions:
        files = files  + glob(path_to_shots + "*."+x);
    
    
    sfiles = load_sent_files();

    return [x for x in files if x not in sfiles];
    
    

    
if __name__ == "__main__":
    
    
    import sys
    
    from getpass import getpass

    #try:
    name = account_user;
    to = mail_to;
    
        #subject = sys.argv[3]
        #msg = sys.argv[4]
    
    

    ga = libgmail.GmailAccount(name, account_pass)

    print "\nPlease wait, logging in..."

    try:
        ga.login()
    except libgmail.GmailLoginFailure:
        print "\nLogin failed. (Wrong username/password?)"
    sys.exit();
    else:
        print "Log in successful.\n"

    new_files =     get_new_files();
    sent_files = [];
    for x in new_files:
        subject = basename(x);
            gmsg = libgmail.GmailComposedMessage(to, subject ,"foto enviada autmaticamente",filenames = [x],);

            if ga.sendMessage(gmsg):
                print "Message sent `%s` successfully." % subject
            sent_files.append(x);
            else:
                print "Could not send message."
    save_new_files(sent_files);

        print "Done."