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')