Hello all,
A while ago I wrote about a script I used to upload files to Dropbox from my Raspberry PI. Since then Dropbox has implemented OAuth v2 and gives you the opportunity to generate a token directly from their website.
With that token you can authenticate directly and run commands. You need Dropbox 2.0+ SDK.
Here’s the new script:
#!/usr/bin/python
# Include the Dropbox SDK libraries
import dropbox
import os
import sys
DEBUG = False
TOKEN = ''
if os.path.exists('token.txt'):
with open('token.txt') as token_f:
TOKEN = token_f.readline().rstrip()
if DEBUG:
print TOKEN
# Create client
client = dropbox.client.DropboxClient(TOKEN)
if DEBUG:
print "linked account:", client.account_info()
noParams = len(sys.argv)
if noParams < 2:
print "Usage: upload_to_dropbox.py <file1> ..."
sys.exit(0)
for idx in range(1, noParams):
f = open(sys.argv[idx])
filename = os.path.basename(sys.argv[idx])
response = client.put_file(filename, f, True)
print "uploaded:", response
Code is also available in my bitbucket: https://bitbucket.org/crazyquark/pydropboxutils
Enjoy.
P.S.
An older commit had some private keys in there but don’t worry, I deleted the credentials from my Dropbox account so they cannot be used anymore.
Plus, the repo used to be private.