#!/usr/bin/env python3
"""Buka post Threads TSC dengan peramban sungguhan, cetak teks post + replies."""
import asyncio, re, sys

URL = sys.argv[1] if len(sys.argv) > 1 else "https://www.threads.com/@theskincode_clinic/post/Deihy3pie4C"


async def main():
    from playwright.async_api import async_playwright
    async with async_playwright() as pw:
        br = await pw.chromium.launch()
        ctx = await br.new_context(
            user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36",
            locale="id-ID", viewport={"width": 1280, "height": 1600})
        hal = await ctx.new_page()
        await hal.goto(URL, wait_until="domcontentloaded", timeout=90000)
        await hal.wait_for_timeout(7000)
        for teks in ("Dismiss", "Tutup", "Close", "Got it"):
            try:
                t = hal.get_by_role("button", name=re.compile(teks, re.I))
                if await t.count():
                    await t.first.click()
                    await hal.wait_for_timeout(1200)
            except Exception:
                pass
        isi = await hal.evaluate("() => document.body.innerText")
        await br.close()
    isi = re.sub(r"\n{3,}", "\n\n", isi)
    print(isi[:6000])


asyncio.run(main())
