47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""wr_key.py <name> — создать API-ключ на /account/keys и вывести его."""
|
|
import json, re, sys, time
|
|
sys.path.insert(0, r"C:/Users/User/tmp")
|
|
import wr_reg
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
|
|
def main():
|
|
name = sys.argv[1] if len(sys.argv) > 1 else "farm"
|
|
with sync_playwright() as p:
|
|
br, ctx, pg = wr_reg.connect(p)
|
|
pg.goto("https://withruntime.com/account/keys", wait_until="domcontentloaded")
|
|
time.sleep(3)
|
|
pg.get_by_role("button", name="New key").first.click()
|
|
time.sleep(2)
|
|
# диалог
|
|
dlg = pg.locator("[role=dialog]")
|
|
print("dialog:", dlg.count())
|
|
inputs = pg.eval_on_selector_all("input:visible", "els=>els.map(e=>({id:e.id,name:e.name,ph:e.placeholder,type:e.type}))")
|
|
print("inputs:", inputs)
|
|
if inputs:
|
|
sel = "input:visible" if not inputs[0].get("id") else "input#%s" % inputs[0]["id"]
|
|
pg.locator(sel).first.click()
|
|
pg.locator(sel).first.type(name, delay=40)
|
|
# кнопки диалога
|
|
btns = [b.inner_text().strip() for b in pg.locator("[role=dialog] button, dialog button").all()]
|
|
print("dlg buttons:", btns)
|
|
for lbl in ("Create", "Create key", "Create API key", "Add"):
|
|
b = pg.get_by_role("button", name=re.compile(lbl, re.I))
|
|
if b.count() and b.first.is_visible():
|
|
b.first.click()
|
|
print("clicked", lbl)
|
|
break
|
|
time.sleep(4)
|
|
txt = pg.inner_text("body")
|
|
print("TEXT:", re.sub(r"\s+", " ", txt)[:800])
|
|
m = re.findall(r"\b(rt_[A-Za-z0-9_\-]{10,}|sk-[A-Za-z0-9_\-]{10,})\b", txt)
|
|
print("KEYS:", m)
|
|
try:
|
|
ctx.storage_state(path=wr_reg.STATE)
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |