Created
February 17, 2012 08:45
-
-
Save zealic/1851902 to your computer and use it in GitHub Desktop.
Use python to link Dropbox fully automated in a text based Linux environment
This file contains 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 python | |
import os | |
import subprocess | |
from signal import * | |
import re | |
import getpass | |
import urllib2 | |
import time | |
COMMAND_TEXT = "./.dropbox-dist/dropbox" | |
def Login(email, password): | |
email = urllib2.quote(email) | |
password = urllib2.quote(password) | |
pLogin = subprocess.Popen('curl -c dropboxCookies https://www.dropbox.com/login', shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
v = pLogin.stdout.read() | |
t = re.search('name="t" value="(.*?)"', v).group(1) | |
print('Retrieved session cookies...'); | |
pLogin = subprocess.Popen('curl -b dropboxCookies -c dropboxCookies -d t=%s -d login_email=%s -d login_password=%s -d login_submit=Log+in https://www.dropbox.com/login' % (t, email, password), shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
v = pLogin.stdout.read() | |
pLogin = subprocess.Popen('curl -b dropboxCookies -c dropboxCookies https://www.dropbox.com/cli_link?host_id=%s' % (host_id), shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
v = pLogin.stdout.read() | |
t = re.search('name="t" value="(.*?)"', v).group(1) | |
pLogin = subprocess.Popen('curl -b dropboxCookies -d t=%s -d password=%s https://www.dropbox.com/cli_link?host_id=%s' % (t, password, host_id), shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
v = pLogin.stdout.read() | |
print('Link procedure done, waiting for dropbox response...'); | |
os.system("killall dropbox") | |
if(os.path.exists(os.path.expanduser("~/.dropbox"))): | |
print("Maybe your client has linked.") | |
exit(1) | |
p = subprocess.Popen(COMMAND_TEXT, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
host_id = "" | |
while(True): | |
line = p.stdout.readline() | |
if(line.find("Client successfully linked") >= 0): | |
print("ALL DONE!") | |
break | |
if host_id: continue | |
match = re.search('host_id=(.*?)&', line) | |
if(match): | |
host_id = match.group(1) | |
print("Input your email : ") | |
email = raw_input() | |
password = getpass.getpass("Enter your password : ") | |
Login(email, password) | |
time.sleep(3) | |
p.send_signal(SIGINT) | |
p.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment