#!/usr/bin/env python3
"""DMark: bandingkan aset plugin pada render CACHE vs render SEGAR — cari penyebab halaman kehilangan isi."""
import re, urllib.request
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"}


def ambil(u):
    r = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=90)
    return r.read().decode("utf-8", "replace"), dict(r.headers)


for label, u in (("CACHE", "https://www.dmark.id/contact/"), ("SEGAR", "https://www.dmark.id/contact/?nowprocket=1")):
    h, head = ambil(u)
    print(f"\n===== {label} ({len(h):,} byte) =====")
    plug = Counter(re.findall(r"/wp-content/plugins/([a-z0-9\-_]+)/", h))
    print("   plugin yang asetnya dimuat:", dict(plug))
    print("   tema:", sorted(set(re.findall(r"/wp-content/themes/([a-z0-9\-_]+)/", h))))
    print("   blok spectra di HTML:", len(re.findall(r"spectra", h, re.I)))
    print("   skema yoast:", "yoast-schema-graph" in h, "| komentar yoast:", "optimized with the Yoast" in h)
    print("   jumlah <h1-6>:", len(re.findall(r"<h[1-6]", h)))
    print("   ada tulisan 'Contact Us'/'Kontak':", ("Contact Us" in h), ("Kontak" in h))
    print("   teks isi (300 char):", re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", h[h.find('<body'):h.find('<body') + 3000]))[:300])
    print("   header: cache-control=", head.get("cache-control"), "| x-cache=", head.get("x-cache"))
