28 lines
1.9 KiB
Python
28 lines
1.9 KiB
Python
#!/opt/pw/bin/python
|
|
"""actual_import.py — the import step of actual_fill.py alone (the first run's click hit the account header's
|
|
„Import", not the dialog's): sign in, open „Családi számla", Import → the CSV → the dialog's own Import button."""
|
|
import os, re
|
|
from playwright.sync_api import sync_playwright
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch(executable_path="/usr/bin/chromium", args=["--no-sandbox"])
|
|
pg = b.new_context(locale="hu-HU", ignore_https_errors=True, viewport={"width": 1366, "height": 900},
|
|
storage_state="/root/work/state-dash.json").new_page()
|
|
pg.goto("https://budget.tester4.test/", wait_until="load"); pg.wait_for_timeout(5000)
|
|
if pg.locator("input[type=password]").count():
|
|
pg.fill("input[type=password]", os.environ["PW"]); pg.keyboard.press("Enter"); pg.wait_for_timeout(6000)
|
|
print("after sign-in:", re.sub(r"\s+", " ", pg.inner_text("body"))[:300])
|
|
if not pg.get_by_text("Családi számla").count() and pg.get_by_text("My Finances").count():
|
|
pg.get_by_text("My Finances").first.click(); pg.wait_for_timeout(8000)
|
|
pg.get_by_text("Családi számla").first.click(); pg.wait_for_timeout(3000)
|
|
with pg.expect_file_chooser(timeout=20000) as fc:
|
|
pg.get_by_role("button", name=re.compile("^Import", re.I)).first.click()
|
|
fc.value.set_files("/root/data/actual/tranzakciok.csv"); pg.wait_for_timeout(5000)
|
|
dlg = pg.locator("[role=dialog]").last
|
|
btns = dlg.locator("button").evaluate_all("els => els.map(e => e.innerText.trim())")
|
|
print("dialog buttons:", btns)
|
|
dlg.locator("button", has_text=re.compile(r"Import", re.I)).last.click()
|
|
pg.locator("[role=dialog]").last.wait_for(state="detached", timeout=180000); pg.wait_for_timeout(5000)
|
|
print("after import:", re.sub(r"\s+", " ", pg.inner_text("body"))[:300])
|
|
pg.screenshot(path="/root/shots/b4-actual-9-imported-desktop-hu.png", full_page=True)
|
|
b.close()
|