• felciano

    Thanks @JonB. I'm looking to cache API keys for Dropbox (see this thread) so "reasonably secure" should probably mean "invisible from access if someone gets access to the device".

    The use case / need is to store short-lived authentication tokens used for Dropbox API calls. Although this pattern-matches against the environment variables option, these tokens need to be refreshed fairly frequently. The refresh is relatively painless/automated, but still results in an updated key values that needs to be stored. I suspect an .env file or similar stored somewhere that the Files app can read it directly is probably not a good solution since these keys might allow access to sensitive information,
    .
    Encrypting a settings file in iCloud at rest might work but I'm not clear how to do that if the python code that would decrypt the data is also stored in iCloud -- wouldn't that mean someone could just read the Python code and figure out how to decrypt it? I might be missing something here.

    I'd prefer something less tied to the Mac ecosystem, but maybe Keychain is the best option to explore?

    posted in Pythonista read more
  • felciano

    For the record, I've also been trying to get an updated version of the official Dropbox library installed via Stash, but no luck. I'm running into the error describe here:

    https://github.com/ywangd/stash/issues/382

    posted in Pythonista read more
  • felciano

    Hi all ---

    Dropbox has started enforcing short-lived OAuth access tokens so it seems that any Pythonista scripts that want to use it will need to know how to either create or refresh access tokens if they've expired. It appears that current versions of the Dropbox Python library include convenience functions for doing this (e.g. get_and_refresh_access_token()) but those are not available in the version of the library that ships with Pythonista.

    Has anyone been able to figure out how to refresh these tokens some other way? Or some other workaround to enable updated tokens to be used in Pythonista scripts?

    Thanks in advance!

    posted in Pythonista read more
  • felciano

    Hi @madivad did you end up finding a solution for this? I need to cache API tokens across Pythonista runs, and am curious to know whether you've found a way to store these outside of the code in a way that is reasonably secure and sharable across devices.

    posted in Pythonista read more
  • felciano

    Thanks @mikael -- I will give that a shot and report back.

    posted in Pythonista read more
  • felciano

    Hi all --

    I'm trying to get Working Copy integration with Pythonista via the "External Files" functionality, so that code can be stored in Github. I am able to access Github repositories to edit and run code from the main Pythonista window, but I can't figure out how to expose one of these scripts as a Share Sheet script in Pythonista.

    In particular, when I'm looking at one of these scripts and choose the little gear icon and tap "Shortcuts... > Share Extension > + [new share extension]", it prompts me to pick the script for the new share extension and my only options are "This iPad" or "iCloud". Is there a way for the script from external files (in this case, Working Copy) to be triggered by the share sheet?

    Thanks!

    posted in Pythonista read more
  • felciano

    I know this is a 3+ year old thread but I still haven't been able to get this to work correctly with Dropbox (or several other apps that expose files through the External Files API).

    I have confirmed that overall the process works as I've been able to get Working Copy to show up as expected as a file provider when I click Pythonista > External Files > Open... However Dropbox always seems to show up disabled and I am unable to browse it to select files.

    Working Copy and Dropbox are both configured as external file providers in the Files app, and I'm able to browse their contents from the Files app. However when trying to browse them from Pythonista, Dropbox remains disabled.

    Is there any other configuration required to fully expose a 3rd party file provider in Pythonista?

    posted in Pythonista read more
  • felciano

    Forgot to reply to close this out: using the get_image version as suggested by @mikael did the trick, at least in terms of saving a second or so in runtime (which is noticeable). Thanks all!

    posted in Pythonista read more
  • felciano

    Thanks for the suggestions @mikael. I actually started playing around with appex and get_image_data but was finding inconsistent data values there. In particular, get_image_data often had a Boolean as value rather than actual data, whereas get_image contained a PIL.PngImagePlugin.PngImageFile. This seems different than the documented behavior from the `appear documentation, but I can’t tell if that is a Pythonista issue or whether Pythonista just passes through the data from the calling app, in which case that is where the issue might lie.

    The source of the image (i.e. the app from which I’m triggering the share sheet) is CalmApp, in case that matters.

    posted in Pythonista read more
  • felciano

    Hi --

    I'm trying to automate some data collection across various app-enabled activities (e.g. meditation) to a central Google Sheets spreadsheet, using Dropbox to collect any associated images. This is implemented via a Pythonista app triggered via the share sheet. For example, after a meditation, I share the final summary view with the script, and it logs some details about the meditation to Google Forms (which ends up in Google Sheets) and saves any image passed to the share sheet to Dropbox. A URL to the uploaded image is included in the Google Forms submission.

    My challenge is that the Dropbox image upload is slow enough to really disrupt my flow, so I'm trying see if there is an obvious way to speed it up. In particular, it looks like I have to explicitly write out the image to a BytesIO stream, even if it is already in the desired format (PNG) -- see uploader code below. Is there a faster way to do this? For example, is there a way to perform these operations in parallel / async i.e. grab the shared link while the image uploads in the background?

    Thanks in advance!

    def upload_image_to_dropbox(image, pathname_in_dropbox):
        with io.BytesIO() as output: # this seems necessary even if image.format is already "PNG"
            image.save(output, format="PNG") 
            contents = output.getvalue()
        dbfile = dbx.files_upload(contents, pathname_in_dropbox, dropbox.files.WriteMode.add, mute=True) # takes a long time
        dbfile_url = dbx.sharing_create_shared_link(pathname_in_dropbox, short_url=False, pending_upload=None)
        link_to_image = dbfile_url.url.replace("?dl=0","?raw=1")
        return link_to_image
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!