Verified Commit c907766b authored by Jakob Moser's avatar Jakob Moser
Browse files

Add basic CLI to sync transactions

parent 355a8f43
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
"""
Connect to a bank account using FinTS
"""
+41 −0
Original line number Diff line number Diff line
import getpass
from pathlib import Path
from typing import Annotated

import typer

from poolpay import db, paths
from poolpay.model.BankAccount import BankAccount

app = typer.Typer()


def _guess_db_path() -> Path:
    # By default, we use a dedicated path for the database containing FinTS data, as in the common deployment,
    # we run two separate instances of the software for that
    fints_db_path = paths.instance_dir / "poolpay.fints.db"

    # Only if that doesn't exist, we fall back to the generic database location
    return fints_db_path if fints_db_path.exists() else paths.db_file


@app.command()
def sync(
    db_path: Annotated[
        Path | None, typer.Option(help="Path to the database file (guessed by default)")
    ] = None,
) -> None:
    """
    Download transactions for all nw bank accounts and store them in the database.
    """
    try:
        db.open(db_path or _guess_db_path())
        for bank_account in BankAccount.get_all():
            password = getpass.getpass(f"Password for {bank_account.user}: ")
            bank_account.sync(password)
    finally:
        db.close()


if __name__ == "__main__":
    app()
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ dependencies = [
    "schwifty>=2026.3.0",
    "sqlalchemy~=2.0.38",
    "textual~=3.1.0",
    "typer>=0.26.7",
]

[tool.ruff.lint]
+44 −0
Original line number Diff line number Diff line
@@ -2,6 +2,15 @@ version = 1
revision = 3
requires-python = ">=3.12"

[[package]]
name = "annotated-doc"
version = "0.0.4"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/57/ba/046ceea27344560984e26a590f90bc7f4a75b06701f653222458922b558c/annotated_doc-0.0.4.tar.gz", hash = "sha256:fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4", size = 7288, upload-time = "2025-11-10T22:07:42.062Z" }
wheels = [
    { url = "https://files.pythonhosted.org/packages/1e/d3/26bf1008eb3d2daa8ef4cacc7f3bfdc11818d111f7e2d0201bc6e3b49d45/annotated_doc-0.0.4-py3-none-any.whl", hash = "sha256:571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320", size = 5303, upload-time = "2025-11-10T22:07:40.673Z" },
]

[[package]]
name = "babel"
version = "2.17.0"
@@ -105,6 +114,15 @@ wheels = [
    { url = "https://files.pythonhosted.org/packages/db/8f/61959034484a4a7c527811f4721e75d02d653a35afb0b6054474d8185d4c/charset_normalizer-3.4.7-py3-none-any.whl", hash = "sha256:3dce51d0f5e7951f8bb4900c257dad282f49190fdbebecd4ba99bcc41fef404d", size = 61958, upload-time = "2026-04-02T09:28:37.794Z" },
]

[[package]]
name = "colorama"
version = "0.4.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
wheels = [
    { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
]

[[package]]
name = "elementpath"
version = "5.1.2"
@@ -417,6 +435,7 @@ dependencies = [
    { name = "schwifty" },
    { name = "sqlalchemy" },
    { name = "textual" },
    { name = "typer" },
]

[package.metadata]
@@ -431,6 +450,7 @@ requires-dist = [
    { name = "schwifty", specifier = ">=2026.3.0" },
    { name = "sqlalchemy", specifier = "~=2.0.38" },
    { name = "textual", specifier = "~=3.1.0" },
    { name = "typer", specifier = ">=0.26.7" },
]

[[package]]
@@ -554,6 +574,15 @@ wheels = [
    { url = "https://files.pythonhosted.org/packages/1d/06/7128b1dee5d616587b5e83597d1e6a651c56668820c3b8f2d7e870c1ae76/sepaxml-2.7.0-py3-none-any.whl", hash = "sha256:6644f695c66c2bf8f49065d4d7b0814da42140d03292131ec08e09798ad07b5d", size = 60537, upload-time = "2025-09-02T12:28:14.702Z" },
]

[[package]]
name = "shellingham"
version = "1.5.4"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", size = 10310, upload-time = "2023-10-24T04:13:40.426Z" }
wheels = [
    { url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
]

[[package]]
name = "spidev"
version = "3.8"
@@ -625,6 +654,21 @@ wheels = [
    { url = "https://files.pythonhosted.org/packages/8d/a7/802690234cdbdf99020c7c55512b5cea8344b6578a40b19f2f863c659867/textual-3.1.1-py3-none-any.whl", hash = "sha256:623fa18be75f8acba6c8d5aca019ff894a9614de8c456574ba53a728c6c44dad", size = 683838, upload-time = "2025-04-22T11:32:46.784Z" },
]

[[package]]
name = "typer"
version = "0.26.7"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "annotated-doc" },
    { name = "colorama", marker = "sys_platform == 'win32'" },
    { name = "rich" },
    { name = "shellingham" },
]
sdist = { url = "https://files.pythonhosted.org/packages/5e/ed/ef06584ccdd5c410df0837951ecd7e15d9a6144ea1bd4c73cecab1a89891/typer-0.26.7.tar.gz", hash = "sha256:e314a34c617e419c091b2830dda3ea1f257134ff593061a8f5b9717ab8dddb3a", size = 201709, upload-time = "2026-06-03T07:18:06.843Z" }
wheels = [
    { url = "https://files.pythonhosted.org/packages/24/25/2201973529af2c954de0bb725323c3aaed6d7f0ceee8f550dec9185df013/typer-0.26.7-py3-none-any.whl", hash = "sha256:5c87cfbc5d34491c5346ebf49c23e18d56ccb863268d3a8d592b26087c2f5e58", size = 122456, upload-time = "2026-06-03T07:18:05.732Z" },
]

[[package]]
name = "typing-extensions"
version = "4.15.0"