# -*- coding: utf-8 -*-
import sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')

with open('upload_response.html', encoding='utf-8', errors='replace') as f:
    html = f.read()

print("=== ALL href LINKS ===")
for m in re.finditer(r'href=["\']([^"\']+)["\']', html, re.I):
    link = m.group(1)
    print("  LINK:", link)

print()
print("=== data- ATTRIBUTES (JS hooks) ===")
for m in re.finditer(r'data-[\w-]+=["\']([^"\']+)["\']', html, re.I):
    print("  DATA:", m.group(0)[:120])

print()
print("=== STATUS / DOWNLOAD related text ===")
for kw in ['download', 'status', 'ready', 'complete', 'done', 'error', 'pending', 'processing', 'result', 'output']:
    idx = html.lower().find(kw)
    if idx >= 0:
        snippet = html[max(0, idx-60):idx+200].replace('\n', ' ').strip()
        print(f"[{kw}]: {snippet}")
        print()
