omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Dropbox access .txt file

    Pythonista
    5
    6
    4682
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • donnieh
      donnieh last edited by

      If I made a Pythonista script and wanted to read/write to a .txt file (like log data) that is in my Dropbox, how would I go ahead and do that?

      I don't need to make a UI like a file picker, just read/write to a .txt file.

      1 Reply Last reply Reply Quote 0
      • donnieh
        donnieh last edited by

        (I have a text file in drop box being updated by some other computer, I want to read that data in a .py script.)

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          1. See: http://omz-forums.appspot.com/pythonista/post/6675908186341376 and follow the steps there to get OMZ's dropboxlogin.py working.
          2. Change filename in the code below and run it.
          3. See: http://omz-software.com/pythonista/docs/ios/dropbox.html for other cool things you can do with the Dropbox API.
          import contextlib, dropboxlogin
          filename = '2048.py'
          dropbox_client = dropboxlogin.get_client()
          with contextlib.closing(dropbox_client.get_file(filename)) as in_file:
              data = in_file.read()
          print data
          
          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            You could also look at just the download_file function in my Dropbox File Picker (and the setup instructions at the top of the Gist). That function can be used without any UI, and it should be relatively easy to write an upload_file in the same way (have a look at the Dropbox Core API which I used directly there).

            The setup process has a few more steps than dropboxlogin, but it should be more reliable overall, since it doesn't require showing a browser etc.

            1 Reply Last reply Reply Quote 0
            • jrh147
              jrh147 last edited by

              I'm trying to do the same here but keep running into a 401 error.

              I followed the above advice, and run the dropboxlogin.py script to test it out and I just get the error. I found this on Linking Dropbox and Pythonista but the instructions seemed to have change for Dropbox.

              I created the app, generated a user token, set it to full Dropbox and then changed the dropboxlogin script to show the app key, the app secret and dropbox for access. That page says you can run the script to test it out but I get a 401 error.

              I try and run the script above, the one where you change the filename and again a 401 error. I really want to be able to do this, to read in data from a CSV on Dropbox, but can't seem to find clear instructions on how to get started. Thanks in advance.

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by JonB

                Here is a 6 liner that simply uploads, then downloads a textfile, which makes use of the generated token to make things easy. You can replace the test string with an open file object

                import dropbox,contextlib
                TOKEN='YOUR ACCESS TOKEN GOES HERE... GENERATE FROM DROPBOX API PAGE'
                d=dropbox.Dropbox(TOKEN)
                d.files_upload('test','/test.txt')
                with contextlib.closing(d.files_download('/test.txt')[1]) as response:
                	print response.content
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors