@button DropboxUploadLEO


/ Published in: Python
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. import mechanize
  2. import sys
  3. from grun import grun
  4.  
  5. def upload_file(local_file,remote_dir,remote_file,email,password):
  6. """ Upload a local file to Dropbox """
  7.  
  8. # Fire up a browser using mechanize
  9. br = mechanize.Browser()
  10.  
  11. # Browse to the login page
  12. br.open('https://www.dropbox.com/login')
  13.  
  14. # Enter the username and password into the login form
  15. isLoginForm = lambda l: l.action == "https://www.dropbox.com/login" and l.method == "POST"
  16.  
  17. try:
  18. br.select_form(predicate=isLoginForm)
  19. except:
  20. print("Unable to find login form.");
  21. exit(1);
  22.  
  23. br['login_email'] = email
  24. br['login_password'] = password
  25.  
  26. # Send the form
  27. response = br.submit()
  28.  
  29. # Add our file upload to the upload form once logged in
  30. isUploadForm = lambda u: u.action == "https://dl-web.dropbox.com/upload" and u.method == "POST"
  31.  
  32. try:
  33. br.select_form(predicate=isUploadForm)
  34. except:
  35. print("Unable to find upload form.");
  36. print("Make sure that your login information is correct.");
  37. exit(1);
  38.  
  39. br.form.find_control("dest").readonly = False
  40. br.form.set_value(remote_dir,"dest")
  41. br.form.add_file(open(local_file,"rb"),"",remote_file)
  42.  
  43. # Submit the form with the file
  44. br.submit()
  45.  
  46. if __name__ == "__main__":
  47. leofolder = sys.path[0]
  48. email = "ENTERYOURDROPBOXEMAIL"
  49.  
  50. #get filename - Is there a variable for this?
  51. @grun
  52. def ask_filename(filename):
  53. """ Enter the name of this LEO file without the extension """
  54. return filename
  55.  
  56. #get password
  57. @grun
  58. def ask_pass(password):
  59. """ Enter your Dropbox Password """
  60. return password
  61.  
  62. filename = ask_filename()
  63. password = ask_pass()
  64.  
  65. fullfilepath = leofolder + "\\" + filename + ".leo"
  66.  
  67. #upload_file("local_filename","/Path/In/Dropbox/","remote_filename","[email protected]","password")
  68. upload_file(fullfilepath,"/AADW-LEO/",filename + ".leo",email,password)
  69. print("Uploaded LEO file")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.