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.


    Save to arbitrary iCloud Drive path in new Pythonista?

    Pythonista
    6
    17
    14570
    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.
    • dueyfinster
      dueyfinster last edited by dueyfinster

      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')
      
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        The path is:

        /private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents

        dueyfinster 1 Reply Last reply Reply Quote 1
        • cvp
          cvp last edited by

          @omz you should perhaps modify File Picker to support local and iCloud files.

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

            @JonB said:

            The path is:

            /private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents

            @JonB I wasn't talking about Pythonista docs, but rather other iCloud Drive folders. I assumed we'd now have access via path. For example:

            os.listdir('/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents')
            

            will work, but:

            os.listdir('/private/var/mobile/Library/Mobile Documents/Desktop')
            

            will not. It seems to only allow access inside the app's folder. I assumed with iOS11 and Files.app, we could have access to a path on iCloud drive.

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @dueyfinster last edited by

              @dueyfinster You're right, I've tested with File Browser which has an iCloud Drive folder.
              It's strange because in the Files app, you can duplicate a file from another folder to this FB folder...

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

                I would advise you to not to do it. All iCloud files / documents should be modified with NSFileCoordinator only. More info in the iCloud File Management. Quote:

                At the heart of the iCloud locking mechanism are file coordinators and file presenters. Whenever you need to read and write a file, you do so using a file coordinator, which is an instance of the NSFileCoordinator class. The job of a file coordinator is to coordinate the reads and writes performed by your app and the sync daemon on the same document. For example, your app and the daemon may both read the document at the same time but only one may write to the file at any single time. Also, if one process is reading the document, the other process is prevented from writing to the document until the reader is finished.

                If you lose something, get weird file content, you know why :)

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @zrzka last edited by

                  @zrzka Thanks a lot, I didn't know that, but really, what do I know? đŸ˜­

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

                    @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.

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

                      @omz same here, but no one never knows. It's better for others to know that smth bad can happen.

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

                        Hey,

                        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 ?

                        Thanks

                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @surg30n last edited by

                          @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...?

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

                            @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

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @surg30n last edited by cvp

                              @surg30n I think that your script copies FROM iCloud, not TO iCloud, thus are you sure the file already exists in iCloud

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

                                @cvp yes. It copies as in example above.
                                File exists in cloud for sure.

                                cvp 1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @surg30n last edited by cvp

                                  @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.

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

                                    @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.

                                    cvp 1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @surg30n last edited by cvp

                                      @surg30n I've tested, with the Pythonista beta, a Siri shortcut performing only this shutil.copyfile, and I get the same error.

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post
                                      Powered by NodeBB Forums | Contributors