If you want to get a "text" file (py,txt,...) from iCloud Drive to Pythonista via the ios File Picker, and if you have the Workflow app, you could:
- create once a Workflow, for instance GetFileFromIcloudDrive, containing only these two actions:
- Get Files
- Show Document Picker on
- Set Variable File (will contain the entire file)
- Get Details of file
- Get Name
- Set Variable FileName (will contain the file name)
- Get Variable File (neded for the next action)
- Get Details of file
- Get File Extension
- Set Variable FileExtension (will contain the file extension)
- Set Text
GetFileFromIcloudDrive:variable_FileName.variable_FileExtension
File
- Copy to Clipboard
see Workflow
When you're "in" the File Picker, you can even get a file from another location, like Google Drive, OneDrive, etc...
- run this script
import webbrowser
import clipboard
import time
# Get a text file from iCloud Drive via File Picker
def get():
clipboard.set('')
webbrowser.open('workflow://x-callback-url/run-workflow?name=GetFileFromIcloudDrive&x-success=pythonista://')
text = clipboard.get()
while text.find('GetFileFromIcloudDrive') < 0:
text = clipboard.get()
time.sleep(0.3)
# Clipboard should be formatted as:
# GetFileFromIcloudDrive:filename.ext\n
# file_content
i = text.find('\n')
if i > 0:
line1 = text[0:i]
filename = line1[len('GetFileFromIcloudDrive:'):]
print('/'+filename+'/')
file = text[i+1:]
locfil = open(filename,'w')
locfil.write(file)
locfil.close()
get()