#!/usr/bin/env python3
"""Cari riwayat pembaruan algoritma Google di sekitar 21-22 Agustus 2026."""
import html, re, urllib.request, urllib.error

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36",
      "Accept-Language": "en-US,en;q=0.9"}

SUMBER = [
    ("Search Engine Land (riwayat update)", "https://searchengineland.com/library/platforms/google/google-algorithm-updates"),
    ("Google Search Status Dashboard", "https://status.search.google.com/products/z8bxq5p5zqb9n8r6y6j6"),
    ("r.jina.ai → SEL", "https://r.jina.ai/https://searchengineland.com/library/platforms/google/google-algorithm-updates"),
]


def ambil(u, timeout=90):
    try:
        r = urllib.request.urlopen(urllib.request.Request(u, headers=UA), timeout=timeout)
        return r.status, r.read().decode("utf-8", "replace")
    except urllib.error.HTTPError as e:
        return e.code, ""
    except Exception as e:
        return 0, str(e)[:90]


for nama, u in SUMBER:
    st, h = ambil(u)
    print(f"\n=== {nama} | status {st} | {len(h):,} byte ===")
    if not h:
        continue
    teks = html.unescape(re.sub(r"<[^>]+>", " ", h))
    teks = re.sub(r"\s+", " ", teks)
    for m in re.finditer(r".{0,150}(?:August|Aug)[^.]{0,40}2026.{0,180}", teks):
        print("   »", m.group(0)[:330])
    for m in re.finditer(r".{0,120}(?:21|22) August 2026.{0,160}", teks):
        print("   ★", m.group(0)[:300])
