#!/usr/bin/env python3
"""DMark: uji render tanpa cache memakai parameter kampanye acak (yang tidak mungkin sudah tercache)."""
import random, re, urllib.request, time
from collections import Counter

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"}
acak = "".join(random.choice("abcdefghijklmnopqrstuvwxyz0123456789") for _ in range(12))

UJI = [
    f"/?utm_source=fb&utm_content={acak}",
    f"/?utm_medium=cpc&utm_campaign={acak}",
    f"/contact/?utm_source=fb&utm_content={acak}",
    f"/?nowprocket=1&utm_source=fb",
    "/?nowprocket=1",
]
for q in UJI:
    t0 = time.time()
    try:
        r = urllib.request.urlopen(urllib.request.Request("https://www.dmark.id" + q, headers=UA), timeout=90)
        h = r.read().decode("utf-8", "replace")
        t = re.search(r"<title[^>]*>(.*?)</title>", h, re.S)
        print(f"   {r.status} | {len(h):>7} byte | {time.time()-t0:5.1f}s | judul: {(t.group(1)[:34] if t else '-'):<36} | "
              f"judul-h: {len(re.findall('<h[1-6]', h)):<3} | {q[:46]}")
    except Exception as e:
        print(f"   GAGAL {str(e)[:60]} | {q[:50]}")
