import asyncio,json,urllib.request,urllib.parse
from playwright.async_api import async_playwright
BASE='https://sma.agentsolutions-mallorca.com'
rows=json.load(open('/tmp/p3_samples.json'))
async def main():
async with async_playwright() as p:
b=await p.chromium.launch(headless=True,executable_path='/snap/bin/chromium',args=['--no-sandbox']); pg=await b.new_page(); out=[]
for row in rows:
sid=row['signal_id']; r=await pg.goto(f'{BASE}/cockpit?highlight={sid}',wait_until='networkidle',timeout=60000)
card=pg.locator(f'#sig-{sid}'); img=card.locator('img');
ui=await img.first.evaluate('(e)=>({naturalWidth:e.naturalWidth,display:getComputedStyle(e).display,src:e.src})') if await img.count() else {'naturalWidth':0,'display':'none','src':None}
status=None; proxy_bytes=0; proxy_ctype=''
if row.get('image_url'):
u=BASE+'/api/img?u='+urllib.parse.quote(row['image_url'],safe='')
try:
with urllib.request.urlopen(u,timeout=30) as resp: status=resp.status; proxy_bytes=len(resp.read()); proxy_ctype=resp.headers.get('Content-Type','')
except Exception as e: status='ERR:'+str(e)
out.append({**row,'proxy_http':status,'proxy_content_type':proxy_ctype,'proxy_bytes':proxy_bytes,'ui_http':r.status if r else None,'ui_image_naturalWidth':ui['naturalWidth'],'ui_image_display':ui['display'],'ui_src':ui['src'],'ui_uses_image':ui['naturalWidth']>0 and ui['display']!='none'})
await b.close(); print(json.dumps(out,ensure_ascii=False,indent=2))
asyncio.run(main())