Save to arbitrary iCloud Drive path in new Pythonista?
Is it possible with the latest Pythonista to save to an iCloud Drive path?
I have a script that saves a CSV file from web scraping to Dropbox. I'm wondering if I can replace this with a local iCloud drive path and have it sync?
icloud_path = '~/iCloud\ Drive/Desktop' icloud_file = open(icloud_path,'w')
@zrzka In my experience, naively writing files in the iCloud container mostly works fine, if you make sure that you're the only one writing (e.g. when you have a script that produces time-stamped files). In short, if you make sure that conflicts are unlikely to arise, you're probably fine, but no guarantees.
@omz same here, but no one never knows. It's better for others to know that smth bad can happen.
icloud_path="/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/" quotes_file_name="my_quotes.txt"; #Sync to iCloud; copyfile(icloud_path+quotes_file_name, current_path+quotes_file_name);
Example code works from Pythonista IDE, but script has no access from widget.
Maybe someone can direct me to some source making it right ? Or not possible to do it ?
@surg30n Sorry, I don't understand. Do you want to execute this little script from the iOS widget screen? If yes, how do tout want to start the process? Without ui, button...?
@cvp no.. script a bit bigger. I write my own quotes to quote-file, separately. Script just gets random one and prints it. So it does it in a widget too as a console output (I added that script to widget).
Just, if script tries get the random line from the quotes-file residing in icloud, it succeeds when I run it from IDE but fails when it runs in widget. ‘Access denied’. (BTW script in widget runs itself every time when i open widgets screen or when it on left side in IOS13 always-on).
This small example here is just to show, how, f.e. Script copies quote-file from local storage to icloud. It works from IDE but fails when running in widget. Just gives out ‘access denied’ referring to icloud
@surg30n I think that your script copies FROM iCloud, not TO iCloud, thus are you sure the file already exists in iCloud
@cvp yes. It copies as in example above.
File exists in cloud for sure.
@surg30n Sorry. You're right. Same error while trying to copy a file from Pythonista iCloud.
Not sure it has ever worked in a widget or if it is since iOS 13 and/or Pythonista beta.
You know that widget process is very limited.
@cvp Thanks for approvement. Thought, maybe there is some appropriate method to copy file from cloud, and simple copy is not allowed in widget from the security pose, but it seems not.
@surg30n I've tested, with the Pythonista beta, a Siri shortcut performing only this shutil.copyfile, and I get the same error.