49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
import subprocess, textwrap, sys
|
|
|
|
remote_script = textwrap.dedent("""
|
|
import requests, json
|
|
U='http://127.0.0.1:2283'
|
|
K='tactility-elias-2af3d9c44b72f987f41afc3438c3dd740862417797a3e5a6'
|
|
P='cbece6a9-720f-482a-a945-c9ba5ca41fd4'
|
|
body=json.dumps({"personIds":[P],"size":1})
|
|
r=requests.post(U+'/api/search/metadata',headers={'x-api-key':K,'Content-Type':'application/json'},data=body,timeout=10)
|
|
print("search", r.status_code)
|
|
j=r.json()
|
|
items=j.get('assets',{}).get('items',[]) if j.get('assets') else j.get('items',[]) or []
|
|
if not items and isinstance(j,list): items=j
|
|
if items:
|
|
aid=items[0]['id']
|
|
print("AID", aid)
|
|
for w,h in [(320,240),(480,320),(320,480),(800,480)]:
|
|
tr=requests.get(f'http://127.0.0.1:8106/resize?assetId={aid}&w={w}&h={h}&format=png',timeout=15)
|
|
print(w,h,tr.status_code,len(tr.content), tr.headers.get('Content-Type'))
|
|
open(f'/tmp/{w}x{h}.png','wb').write(tr.content)
|
|
from PIL import Image
|
|
for w,h in [(320,240),(480,320),(320,480),(800,480)]:
|
|
try:
|
|
im=Image.open(f'/tmp/{w}x{h}.png')
|
|
print(f'PIL {w}x{h} -> {im.size}')
|
|
except Exception as e:
|
|
print(f'PIL fail {w}x{h}', e)
|
|
import os
|
|
print("ls tmp ok")
|
|
for f in ["/tmp/320x240.png","/tmp/480x320.png","/tmp/320x480.png","/tmp/800x480.png"]:
|
|
print(f, os.path.getsize(f) if os.path.exists(f) else "missing")
|
|
else:
|
|
print("no items")
|
|
""")
|
|
|
|
# write remote script to imac first then exec from imac to FamReynaServer
|
|
# Step 1: ssh imac -> ssh FamReynaServer python3
|
|
import shlex
|
|
# Use a simple approach: scp file to FamReynaServer via imac jump
|
|
# Actually easier: from this host (pi) ssh to FamReynaServer directly
|
|
|
|
cmd = ["ssh","-o","ConnectTimeout=10","-o","StrictHostKeyChecking=no","FamReynaServer","python3"]
|
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
out, err = p.communicate(input=remote_script, timeout=30)
|
|
print("STDOUT:\n", out)
|
|
print("\nSTDERR:\n", err)
|
|
print("RC", p.returncode)
|