I’ve created a script in “Script Library/iCloud” using pythonista. The script creates a file and saves some cached geolocation data using the below code.
my_people = {}
my_people_file = 'contacts-data.json'
# populate my_people dictionary with data
def save_cache():
json_text = json.dumps(my_people)
with open(my_people_file, 'w') as f:
f.write(json_text)
This seemed to work fine initially. I only run the script from a single device. I run this script which builds the dictionary with geolocation data and saves it to the file. Once the cache file is built, I have another script which loads the cache file and uses it for other purposes. Once the cache file is created it is not written again, it’s only read from the other script. In other words, I'm not repeatedly writing to this file or doing so from multiple devices.
I noticed, sometime later, that the cache file created in “Script Library/iCloud” had been renamed from ‘contacts-data.json' to ‘contacts-data 2.json'.
My thought was some sort of cloud sync issue but as I said I only am using a single device and only writing it once. I store the scripts in the iCloud area so they’re backed up. Since the script is there, saving the file with the above also saves it there in the same area.
Trying to manually rename it and remove the ‘ 2’ doesn’t seem to work. It won’t let me change the name. When this happens I have to manually delete the cache file and run the script to rebuild it.
Anyone else run into this? I wonder if I need to direct the saving of this cache file to the device local area despite the script running from the iCloud area. Is that possible? Is there a special path prefix I can use when saving the file from python which will direct it to local storage instead of iCloud? Is there a known issue saving a file from a script using the code I provided when that script itself is saved in the “Script Library/iCloud” area?