#!/usr/bin/env python3
"""Run this ON YOUR OWN COMPUTER, once, to capture an Absorb admin session for the SCORM worker.

    pip install playwright
    python -m playwright install chromium
    python absorb_login_helper.py https://YOUR-TENANT.myabsorb.com/admin

A browser window opens. Sign in as the migration admin (complete MFA). When you can see the
admin dashboard, come back to this terminal and press Enter. The script writes
absorb_state.json next to itself. Upload that file on the Content page of the migration tool.

The file holds session cookies for the Absorb admin: treat it like a password, delete it
after uploading, and sign that admin out of Absorb when the migration window closes.
"""
import sys
from playwright.sync_api import sync_playwright

url = sys.argv[1] if len(sys.argv) > 1 else input("Absorb admin URL: ").strip()
with sync_playwright() as p:
    b = p.chromium.launch(headless=False)
    ctx = b.new_context(viewport={"width": 1440, "height": 1000})
    page = ctx.new_page()
    page.goto(url)
    input("\nSign in (including MFA). When the admin dashboard is showing, press Enter here... ")
    ctx.storage_state(path="absorb_state.json")
    print("Saved absorb_state.json — upload it on the Content page, then delete this copy.")
    b.close()
