57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
#!/opt/pw/bin/python
|
|
"""actual_fill.py — Kata signs in to Actual Budget, starts a fresh budget, adds a bank account and imports the 200
|
|
synthetic HUF transactions through Actual's own „Import" dialog (B4). Env PW. Prints each step; screenshots each step."""
|
|
import os, re, sys, time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
OUT = "/root/shots/b4-actual"
|
|
n = [0]
|
|
|
|
|
|
def shot(pg, name):
|
|
n[0] += 1
|
|
pg.evaluate("document.querySelectorAll('input[type=password]').forEach(e => e.value = '')")
|
|
pg.screenshot(path=f"{OUT}-{n[0] + 2}-{name}-desktop-hu.png", full_page=True)
|
|
|
|
|
|
def text(pg):
|
|
return re.sub(r"\s+", " ", pg.inner_text("body"))[:400]
|
|
|
|
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch(executable_path="/usr/bin/chromium", args=["--no-sandbox"])
|
|
ctx = b.new_context(locale="hu-HU", ignore_https_errors=True, viewport={"width": 1366, "height": 768},
|
|
storage_state="/root/work/state-dash.json")
|
|
pg = ctx.new_page()
|
|
pg.goto("https://budget.tester4.test/", wait_until="load"); pg.wait_for_timeout(5000)
|
|
pg.fill("input[type=password]", os.environ["PW"]); pg.keyboard.press("Enter"); pg.wait_for_timeout(6000)
|
|
print("1 after sign-in:", text(pg)); shot(pg, "signed-in")
|
|
for label in ("Start budgeting", "Start fresh", "Create new file", "Start using Actual"):
|
|
loc = pg.get_by_text(label, exact=False)
|
|
if loc.count():
|
|
loc.first.click(); pg.wait_for_timeout(6000); print("2 pressed", repr(label), "->", text(pg)); break
|
|
shot(pg, "budget")
|
|
for label in ("Add account", "Add an account", "+ Add account"):
|
|
loc = pg.get_by_text(label, exact=False)
|
|
if loc.count():
|
|
loc.first.click(); pg.wait_for_timeout(2500); print("3 pressed", repr(label), "->", text(pg)); break
|
|
for label in ("Create a local account", "Create local account", "Add local account"):
|
|
loc = pg.get_by_text(label, exact=False)
|
|
if loc.count():
|
|
loc.first.click(); pg.wait_for_timeout(2000); break
|
|
shot(pg, "account-dialog")
|
|
inputs = pg.locator("[role=dialog] input, .modal input, input[name=name]")
|
|
print("4 dialog inputs:", inputs.count())
|
|
if inputs.count():
|
|
inputs.first.fill("Családi számla")
|
|
pg.get_by_role("button", name=re.compile("Create", re.I)).last.click(); pg.wait_for_timeout(4000)
|
|
print("5 after create:", text(pg)); shot(pg, "account")
|
|
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)
|
|
print("6 import dialog:", text(pg)); shot(pg, "import-dialog")
|
|
btn = pg.get_by_role("button", name=re.compile(r"^Import\b", re.I))
|
|
btn.last.click(); pg.wait_for_timeout(8000)
|
|
print("7 after import:", text(pg)); shot(pg, "after-import")
|
|
b.close()
|