Return to Snippet

Revision: 49029
at July 15, 2011 00:08 by eristoddle


Updated Code
import mechanize
import sys
from grun import grun

def upload_file(local_file,remote_dir,remote_file,email,password):
    """ Upload a local file to Dropbox """
    
    # Fire up a browser using mechanize
    br = mechanize.Browser()
    
    # Browse to the login page
    br.open('https://www.dropbox.com/login')
    
    # Enter the username and password into the login form
    isLoginForm = lambda l: l.action == "https://www.dropbox.com/login" and l.method == "POST"
    
    try:
        br.select_form(predicate=isLoginForm)
    except:
        print("Unable to find login form.");
        exit(1);
    
    br['login_email'] = email
    br['login_password'] = password
    
    # Send the form
    response = br.submit()
    
    # Add our file upload to the upload form once logged in
    isUploadForm = lambda u: u.action == "https://dl-web.dropbox.com/upload" and u.method == "POST"

    try:
        br.select_form(predicate=isUploadForm)
    except:
        print("Unable to find upload form.");
        print("Make sure that your login information is correct.");
        exit(1);
        
    br.form.find_control("dest").readonly = False
    br.form.set_value(remote_dir,"dest")
    br.form.add_file(open(local_file,"rb"),"",remote_file)
    
    # Submit the form with the file
    br.submit()
    
if __name__ == "__main__":
    leofolder = sys.path[0]
    email = "ENTERYOURDROPBOXEMAIL"
    
    #get filename - Is there a variable for this?
    @grun
    def ask_filename(filename):
        """ Enter the name of this LEO file without the extension """
        return filename
        
    #get password
    @grun
    def ask_pass(password):
        """ Enter your Dropbox Password """
        return password
        
    filename = ask_filename()
    password = ask_pass()
    
    fullfilepath = leofolder + "\\" + filename + ".leo"
    
    #upload_file("local_filename","/Path/In/Dropbox/","remote_filename","[email protected]","password")
    upload_file(fullfilepath,"/AADW-LEO/",filename + ".leo",email,password)
    print("Uploaded LEO file")

Revision: 49028
at July 14, 2011 05:39 by eristoddle


Initial Code
import mechanize
import os
from grun import grun

def upload_file(local_file,remote_dir,remote_file,email,password):
    """ Upload a local file to Dropbox """
    
    # Fire up a browser using mechanize
    br = mechanize.Browser()
    
    # Browse to the login page
    br.open('https://www.dropbox.com/login')
    
    # Enter the username and password into the login form
    isLoginForm = lambda l: l.action == "https://www.dropbox.com/login" and l.method == "POST"
    
    try:
        br.select_form(predicate=isLoginForm)
    except:
        print("Unable to find login form.");
        exit(1);
    
    br['login_email'] = email
    br['login_password'] = password
    
    # Send the form
    response = br.submit()
    
    # Add our file upload to the upload form once logged in
    isUploadForm = lambda u: u.action == "https://dl-web.dropbox.com/upload" and u.method == "POST"

    try:
        br.select_form(predicate=isUploadForm)
    except:
        print("Unable to find upload form.");
        print("Make sure that your login information is correct.");
        exit(1);
        
    br.form.find_control("dest").readonly = False
    br.form.set_value(remote_dir,"dest")
    br.form.add_file(open(local_file,"rb"),"",remote_file)
    
    # Submit the form with the file
    br.submit()
    
if __name__ == "__main__":
    leofolder = str(os.getenv("HOME")) + "\\.leo\\"
    email = ""
    
    #get filename - Is there a variable for this?
    @grun
    def ask_filename(filename):
        """ Enter the name of this LEO file without the extension """
        return filename
        
    #get password
    @grun
    def ask_pass(password):
        """ Enter your Dropbox Password """
        return password
        
    filename = ask_filename()
    password = ask_pass()
    
    fullfilepath = leofolder + filename + ".leo"
    
    #upload_file("local_filename","/Path/In/Dropbox/","remote_filename","[email protected]","password")
    upload_file(fullfilepath,"/LEO/",filename + ".leo",email,password)
    print("Uploaded LEO file")

Initial URL


Initial Description
Created to have a LEO editor file upload itself to dropbox. Just replace your dropbox email in the script. The script will ask you the name of the file without the extension, then will ask for your password and finally it uploads the file.

Initial Title
@button DropboxUploadLEO

Initial Tags
python

Initial Language
Python