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.


    Best method to transfer data to PC

    Pythonista
    data transfer
    4
    6
    3737
    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.
    • HT
      HT last edited by

      Hi,

      I've got an app in which the user draws multiple images in succession. The images are stored in an array. I'm wondering what the best method would be to transfer that data to a computer.

      Unfortunately I can't get the dropbox synchronator to work. An alternative I tried is to send a mail with the data. But I don't know how to attach the images or how to create a text file with the pixel Matrix that I could attach.

      Any pointers?

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

        @HT If your PC is WiFi connected to your iDevice, and if the PC runs a (S)FTP server (standard in Windows or Mac OS), you could send it via (S)FTP, what is quicker than attach an image to an email, send it, receive the mail, detach...

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

          Here’s something you can start from. This one is meant to be placed in the wrench menu, either sending the file being edited or the whole directory to the SFTP server, then executing the code and returning the output, i.e. a fast-feedback development environment for a headless server.

          For your purposes, you could save the images to a directory, then send them all to a server.

          #coding: utf-8
          import paramiko
          import editor, console
          import os.path
          import sys
          
          console.clear()
          
          local_path = editor.get_path()
          remote_path = os.path.basename(local_path)
          local_dir_path = os.path.dirname(local_path)
          remote_dir_path = local_dir_path.split('/')[-1]
          
          server_address = "1.1.1.1"
          server_port = 22
          username = "username"
          password = "password"
          
          print('Open SSH connection')
          s = paramiko.SSHClient()
          s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          s.connect(server_address, server_port, username=username, password=password, timeout=4)
          sftp = s.open_sftp()
          
          fixed_local_root = None
          fixed_remote_root = 'magicmirror'
          try:
            sftp.mkdir(fixed_remote_root)
          except:
            pass # Ok if already exists
          
          if sys.argv[1] == 'dir':
            print('--- Send directory')
          
            #sftp.put(local_dir_path, remote_dir_path)
            #parent = os.path.split(local_dir_path)[1]
            prefix_len = len(local_dir_path)
            for walker in os.walk(local_dir_path):
              remote_sftp_path = remote_dir_path +  walker[0][prefix_len:]
              if remote_sftp_path.endswith('/'):
                remote_sftp_path = remote_sftp_path[:-1]
              try:
                pass
                #sftp.mkdir(os.path.join(remotepath, walker[0]))
              except:
                pass
              for file in walker[2]:
                print('put', os.path.join(walker[0],file), remote_sftp_path + '/' + file)
                #sftp.put(os.path.join(walker[0],file),os.path.join(remotepath,walker[0],file))
          else:
            print('--- Send file')
            sftp.put(local_path, remote_path)
          
          if sys.argv[1] == 'run':
          
            print('--- Run it')
            stdin, stdout, stderr = s.exec_command('python3 ' + remote_path)
            
            for line in stdout.readlines():
              print(line.rstrip('\n'))
            
            s.close()
            
            print('--- Done')
            
            for line in stderr.readlines():
              print('ERROR:', line.rstrip('\n'))
              
          print('--- Complete')
          
          1 Reply Last reply Reply Quote 0
          • HT
            HT last edited by HT

            Unfortunately I don't have access to a sftp server. I've got this part of the code, which sends me a mail. I just can't get it to attach the image to the mail:

            
            image = photos.save_image(img)
            
            to = 'receiver'
                                    subject = 'data'
                                    gmail_pwd = 'password'
                                    gmail_user = 'sender'
                                    attachment = self.table
                                    print('Connecting...')
                                    smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
                                    console.show_activity()
                                    smtpserver.ehlo()
                                    smtpserver.starttls()
            
                                smtpserver.ehlo
                                smtpserver.login(gmail_user, gmail_pwd)
                                # 
                                print('Preparing message...')
                                outer = MIMEMultipart()
                                outer['Subject'] = subject
                                outer['To'] = to
                                outer['From'] = gmail_user
                                outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
                                attachment = get_attachment(image)
                                outer.attach(attachment)
                                composed = outer.as_string()
            
                                print('Sending...')
                                smtpserver.sendmail(gmail_user, to, composed)
                                smtpserver.close()
                                console.hide_activity()
                                print('Done.')
            

            It prints out "Get_attachment is not defined"

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

              @HT I use this code

              # coding: utf-8
              import smtplib # for sending an email
              # email package needed modules
              from email.mime.image import MIMEImage
              from email.mime.multipart import MIMEMultipart
              
              import photos
              from PIL import Image
              
              def main():			
              	# Create the container email message.
              	me = 'your email'
              	msg = MIMEMultipart()
              	msg['Subject'] = 'this is the subject'
              	msg['From'] = me
              	msg['To'] = me
              	msg.preamble = 'Send me a photo'
              
              	sel_photo = photos.pick_asset(assets=photos.get_assets(media_type='photo'),multi=False)		
              	photo = sel_photo.get_image_data().getvalue()
              	img = MIMEImage(photo)
              	msg.attach(img)
              
              	# Send the email via our own SMTP server.
              	s = smtplib.SMTP('your smtp server')
              	s.sendmail(me, me, msg.as_string())
              	s.quit()
              
              # check if the script is running instead of 	be imported
              if __name__ == '__main__':
              	main()	
              
              1 Reply Last reply Reply Quote 0
              • scofficial
                scofficial last edited by scofficial

                Hey,
                There are many other ways to send data to your pc, the one I particularly prefer is uploading the data to a drive and downloading it on the required device. You may also try FTP server. However, the easiest method would be to use different applications that send songs, images to devices using wifi like ShareIt. You could also use the inbuilt bluetooth in your devices, if it is available. Try transferring https://sc-downloader.net/ songs with above mentioned ways to know which one is best suited for your device.

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