Day Six: Dropbox Access

Happened almost by accident and was very quick and easy, well enough to keep me tapping away for a day. The key proviso is that the interface is command line driven and utilities python (specifically the python SDK 1.4.1).

First Step is to down the necessary additions to the pre-installed pythons (2.4, 2.5 and 2.6 – 2.6 is the default so we stick with that). The sdk build process needs setuptools so download and install:

$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
$ tar xzf setuptools-0.6c11.tar.gz
$ cd setuptools-0.6c11
$ sudo python setup.py install

Then we do the same with the Dropbox sdk:

$ mget https://www.dropbox.com/static/developers/dropbox-python-sdk-1.4.1.zip
$ unzip dropbox-python-sdk-1.4.1.zip
$ cd dropbox-1.4.1
$ sudo python setup.py install

The Dropbox python will need to declared as an app to access the Dropbox and we do that here:

Make a note of the app id and secret code to add to the python code later.

Time to test, which we do my editing the cli_client.py in the example directory and adding the two ids and changing the access method to ‘dropbox’

Advertisements
This entry was posted in Dropbox, Python, Software. Bookmark the permalink.

17 Responses to Day Six: Dropbox Access

  1. chteuchteu says:

    Hey !
    What is the aim of this Python script ? The same that de Dropbox command line app in Linux ? (syncing Dropbox folder with dropbox start, dropbox status, dropbox stop, …)
    Or just to download files one by one ?

  2. chrisgadget says:

    The dropbox script enables a interactive commands to be sent to dropbox. You change directory with cd and upload/download files. I use it to retrieve a specific set of files in a fixed directory. Still in the process of converting it to symbian python though.

    • chteuchteu says:

      Thank you for the reply !
      Ok, do you know if there is any way of syncing Dropbox folder on the Raspberry ?
      Dropbox deb can’t be installed on it…

      • chrisgadget says:

        I did have a look around for a syncing script (in python) but found nothing. My use case would be a one way sync which can simply be achieved by dragging the whole directory down.

  3. Pingback: Dropbox for the Raspberry Pi (sort of) | Jeff's Skinner Box

  4. Pingback: Raspberry Pi + Dropbox Sync

  5. Jeremy says:

    Hi, I’m having some trouble and I was wondering if you could provide some direction? I’ve followed the directions to install the python and dropbox SDKs on my Raspberry Pi (running Raspian Wheezy). I’ve added my app key and secret, but when I try to run the script, Python complains that it can’t find the dropbox modules. Any ideas?

    pi@jeremy-raspi:~/Downloads/dropbox-1.4.1/example$ python ./cli_client.py
    Traceback (most recent call last):
    File “./cli_client.py”, line 7, in
    from dropbox import client, rest, session
    ImportError: No module named dropbox

    • chrisgadget says:

      After adding your app key and secret code to cli_client.py, did you install the dropbox python library via ‘sudo python setup.py install -f’

      I have just rebuilt my pi with the latest build and it has worked fine.

  6. effemmeffe says:

    hi. have you ever found a way to automatically sync the dropbox folder on your rpi?

    • chrisgadget says:

      No afraid not, my use case for dropbox is for one way transfer.

      • effemmeffe says:

        i don’t understand what you mean with one way transfer

      • chrisgadget says:

        I use a bash script to login to my dropbox and cd to a dropbox directory, where I download a selection of files – my primary case is all the python files in a dropbox directory – I basically develop on my windows PC and store key files in my dropbox.

      • effemmeffe says:

        Then your setup isn’t so different from what I want: I need to put some files in a choosen directory from everywhere end have those files automatically downloaded in a choosen directory on the RPi.
        But the cli_client.py allows me to login and get files, but I don’t know how to do it without interaction…

      • chrisgadget says:

        I took the code of client.py, tweaked it and then accessed a CD, LS and looped through the LS list, downloading each file:


        def updateLocalCache(update=None):
        "Update the Database TSV and Homework Files on the local device"
        myConfig = config.Config()
        destination = myConfig.getTsvDirectory()
        term = DropboxTerm(APP_KEY, APP_SECRET)
        term.cd('Teaching')
        term.cd('Current Database')
        if os.path.exists(destination):
        progress = 0.0
        try:
        databaseFiles = term.ls()
        for item in databaseFiles:
        term.downloadFile(item,destination)
        except:
        raise DropboxException('Database Problem retrieving '+item)
        progress = 10.0
        if update != None:
        update(progress)
        try:
        term.cd ('/')
        term.cd ('Teaching')
        term.cd ('Homework files')
        homeworkFiles = term.ls()
        except:
        raise DropboxException('Homework Problem retrieving '+item)
        destination = myConfig.getMyMathsDirectory()
        for item in homeworkFiles:
        term.downloadFile(item,destination)
        progress += 100.0/len(homeworkFiles)
        if update != None:
        update(progress)
        progress = 100
        if update != None:
        update(progress)
        else:
        raise DropboxException('Local Cache does not exist ('+destination+')')

        This definition is called via a thread – the progress references are UI feedback

  7. Pingback: Raspberry Pi + Dropbox Sync | Application Server

  8. Tauriq says:

    hy Mr.. i want to ask you..
    while I write script $ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
    but i’cant finish intsall it,,,only show..
    ERROR: The certificate of `pypi.python.org’ is not trusted.
    The certificate has not yet been activated
    i dont know it… i hope you can help me.. thank you

    • chrisgadget says:

      I have suspended any dropbox python stuff for the time being. You could try googling for an alternative location for the sources.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s