Python (requests)

"""
HOW TO RUN:
1. Ensure you have Python installed.
2. Install the required dependency 'httpx' by running:
   pip install httpx
3. Save this file as 'scan_trust.py'.
4. Run the script:
   python scan_trust.py
"""

import httpx
import json

API_BASE_URL = "https://trust-sse.oten.com"
API_KEY = "ot_live_-d5Il4kuuv..."
URL_TO_SCAN = "https://google.com"

def scan_url(url: str, lang: str = "en"):
    with httpx.Client(timeout=120.0) as client:
        with client.stream(
                "GET",
                f"{API_BASE_URL}/api/v1/scan-url",
                params={"url": url, "lang": lang},
                headers={"Authorization": f"Bearer {API_KEY}"},
        ) as response:
            print(f"Status: {response.status_code}")
            print(f"Headers: {dict(response.headers)}\n")

            for line in response.iter_lines():
                if not line:
                    continue

                if line.startswith("event:"):
                    event_type = line.split(":", 1)[1].strip()
                    print(f"[{event_type}]", end=" ")

                elif line.startswith("data:"):
                    data_str = line.split(":", 1)[1].strip()
                    try:
                        data = json.loads(data_str)
                        print(json.dumps(data, indent=2, ensure_ascii=False))
                    except json.JSONDecodeError:
                        print(data_str)

                elif line.startswith("id:"):
                    event_id = line.split(":", 1)[1].strip()
                    print(f"id={event_id}")


if __name__ == "__main__":
    scan_url(URL_TO_SCAN)

Last updated