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.


    Robocopy entire photo directory to NAS?

    Pythonista
    5
    21
    4387
    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.
    • margusch
      margusch last edited by

      Hi guys!

      Before I buy pythonista I'd like to ask if there is any possibility to build a application which gets triggered via shortcuts daily and 'robocopys'/mirrors my photos to a certain folder on my NAS.

      I know that you can connect via smbclient() and retrieve the last "x" photos. But is it possible to copy the delta to the NAS? I do not want to check every photo everytime if it already exists on the NAS by hand.

      Thank you very much!

      cvp mikael 4 Replies Last reply Reply Quote 0
      • cvp
        cvp @margusch last edited by cvp

        @margusch your script needs only to store in a local file the highest date-time of the photos that you send to your NAS and only send newer photos.

        Édit: personally, I keep a thumb copy of the photo, with the same file name, after having sent to the NAS, so I know which ones is already backuped. Obviously, this works if you don't have millions of photos.

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

          @margusch or at start of your script, you can ask a list of the photos names already on your NAS, and, by program, not by hand, compare if new local photos already exist in the list.

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

            @margusch said:

            triggered via shortcuts

            And yes, you can define an automation which is an automatic shortcut which launch's a Pythonista script daily at a certain hour.

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

              @cvp said:

              @margusch your script needs only to store in a local file the highest date-time of the photos that you send to your NAS and only send newer photos.

              Édit: personally, I keep a thumb copy of the photo, with the same file name, after having sent to the NAS, so I know which ones is already backuped. Obviously, this works if you don't have millions of photos.

              Thats a good idea!
              Would you mind sharing your code with me?

              I am thinking if buying the app "PhotoSync" wouldn't just do the job..

              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @margusch last edited by cvp

                @margusch said:

                I am thinking if buying the app "PhotoSync" wouldn't just do the job..

                It is sure that to buy Pythonista only for this job is not very profitable.

                Édit: be careful that PhotoSync may have an annual fee for some functionalities.
                Check also FileBrowser Pro with backup/sync features.

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

                  @margusch said:

                  Would you mind sharing your code with me?

                  Not easy to extract quickly needed parts of code but be sure that if/when you buy Pythonista, I could help you

                  It would depend of:

                  • are your photos in camera roll or local directory of Pythonista or in Files app
                  • do you want to keep original
                  • do you want to keep a thumb in local Pythonista file
                  • how much photos
                  • which solution: smb or ftp or sftp
                  • sure that no duplicate file names (if yes, more complex process)
                  • work with a control file or each time compare NAS directory (quickly downloaded)
                  • quid if you want to delete a local photo, does the deletion on NAS must occur
                  • which NAS, for instance Synology has a synchronization function included
                  • etc...
                  1 Reply Last reply Reply Quote 0
                  • margusch
                    margusch @cvp last edited by

                    @cvp Thank you very much for your help!

                    I will try FileBrowser Pro and PhotoSync and if they are working fine I will go with one of that.

                    cvp 2 Replies Last reply Reply Quote 0
                    • cvp
                      cvp @margusch last edited by

                      @margusch here, little quick and dirty, but tested, script

                      from   ftplib import FTP
                      from   objc_util import *
                      import photos
                      
                      # get photos from NAS
                      user = 'admin'
                      pwd = '...'
                      ip = '192.168.0.47'
                      ftp = FTP(ip) # Connect NAS
                      ftp.encoding = 'utf-8'
                      ftp.login(user,pwd)
                      remote_folder = 'Photos/'
                      filesnas= ftp.nlst(remote_folder+'*')
                      
                      # get photos from camera roll
                      for asset in photos.get_assets():
                      	fname = str(ObjCInstance(asset).valueForKey_('filename'))
                      	if (remote_folder+fname) not in filesnas:
                      		b = asset.get_image_data(original=False)	# file as io.BytesIO
                      		ftp.storbinary('STOR '+remote_folder+fname, b,blocksize=32768)
                      		print('sent:',fname)
                      									
                      ftp.quit() # Disconnect
                      
                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @margusch last edited by cvp

                        @margusch said:

                        I will try FileBrowser Pro and PhotoSync and if they are working fine I will go with one of that.

                        Compare the prices but if you know Python, you'll have a lot of fun with Pythonista for solving new ideas.

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

                          user = 'admin'
                          pwd = '...'
                          ip = '192.168.0.47'
                          ftp = FTP(ip) # Connect NAS
                          ftp.encoding = 'utf-8'
                          # …
                          ftp.quit() # Disconnect
                          # —>
                          with FTP(host='192.168.0.47', user='admin', passwd='…', encoding='utf-8') as ftp:
                          

                          https://docs.python.org/3/library/ftplib.html#ftplib.FTP

                          cvp 3 Replies Last reply Reply Quote 0
                          • cvp
                            cvp @ccc last edited by

                            @ccc I didn't know that the quit was not mandatory. Anyway, nicer as usual.

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

                              @ccc thus, even ftp.login(..) is not necessary

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

                                @ccc said:

                                with FTP(host='192.168.0.47', user='admin', passwd='…', encoding='utf-8') as ftp:

                                encoding not a parameter of FTP.init, thus

                                from   ftplib import FTP
                                from   objc_util import *
                                import photos
                                
                                with FTP(host='192.168.0.47', user='admin', passwd='...') as ftp:
                                	ftp.encoding='utf-8'
                                	# get photos from NAS
                                	remote_folder = 'Photos/'	
                                	filesnas= ftp.nlst(remote_folder+'*')
                                	# get photos from camera roll
                                	for asset in photos.get_assets():
                                		fname = str(ObjCInstance(asset).valueForKey_('filename'))
                                		if (remote_folder+fname) not in filesnas:
                                			b = asset.get_image_data(original=False)	# file as io.BytesIO
                                			ftp.storbinary('STOR '+remote_folder+fname, b,blocksize=32768)
                                			print('sent:',fname)									
                                
                                1 Reply Last reply Reply Quote 0
                                • ccc
                                  ccc last edited by

                                  Python < 3.9 did not have an encoding parameter: https://docs.python.org/3.8/library/ftplib.html#ftplib.FTP but was added in Py3.9

                                  1 Reply Last reply Reply Quote 1
                                  • mikael
                                    mikael @margusch last edited by

                                    @margusch: "build a application which gets triggered via shortcuts daily"

                                    Good to note that it will (probably) not happen in the background on a locked device, so this would in effect be more like a reminder and an easier way for you to start the process.

                                    cvp 2 Replies Last reply Reply Quote 0
                                    • cvp
                                      cvp @mikael last edited by

                                      @mikael said:

                                      Good to note that it will (probably) not happen in the background on a locked device

                                      I think that the shortcut runs in the background of a locked device (don't remember if I had tested) but if the shortcut launchs an app, this one would not, excepted perhaps if Pyto in background mode, not tested.

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

                                        @mikael but perhaps could you SFTP a file to the NAS via the SSH action of shortcut....

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

                                          @mikael I had tested background in locked device for this topic

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

                                            @cvp, thanks, really nice if so. I remember some of my earlier attempts being somewhat hit and miss.

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