Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

License #51

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@

async def main() -> None:
"""Main function."""
sf: SimpleFin = SimpleFin("https://localhost:8000")
sf: SimpleFin = SimpleFin(access_url)
data = await sf.fetch_data()
print(data)
# print(data)


for account in data.accounts:
print(account.name, account.org.name, account.possible_error)
print(account.balance_date)
print(account.last_update_utc)
print(account.last_update_timestamp)


# Run the async main function
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "Development environment with Python 3.12 and Poetry";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShell = pkgs.mkShell {
buildInputs = [
pkgs.python312Full
pkgs.poetry
];

shellHook = ''
export POETRY_VIRTUALENVS_IN_PROJECT=true
poetry install
'';
};
});
}
611 changes: 304 additions & 307 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[tool.poetry]
name = "simplefin4py"
version = "0.0.14"
version = "0.0.17"
description = ""
authors = ["Jeef <[email protected]>"]
readme = "README.md"
license = "MIT"


[tool.poetry.dependencies]
python = "^3.11"
aiohttp = ">=3.9.1"
dataclasses-json = "^0.6.3"


[tool.poetry.group.dev.dependencies]
pre-commit = "^3.6.0"
ruff = "^0.1.9"
Expand Down
19 changes: 14 additions & 5 deletions simplefin4py/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,28 @@ class Account:
balance: str
available_balance: str = field(metadata=config(field_name="available-balance"))
balance_date: datetime = field(metadata=config(field_name="balance-date", decoder=datetime.datetime.fromtimestamp))

transactions: list[Transaction]
holdings: list[Holding] = field(default_factory=list)
extra: dict | None = None # type: ignore

# Optional Error field added by me
possible_error: bool = False

def _timestamp_to_utc(ts: float) -> datetime:
return datetime.fromtimestamp(ts, tz=datetime.timezone.utc)


@property
def last_update(self) -> datetime.datetime:
"""Return the last update as a datetime object."""
return datetime.datetime.fromtimestamp(
self.balance_date, tz=datetime.timezone.utc
)
def last_update_utc(self) -> datetime.datetime:
"""Return the last update as a datetime object with a timezone."""
if self.balance_date.tzinfo is None:
return self.balance_date.replace(tzinfo=datetime.timezone.utc)

@property
def last_update_timestamp(self) -> float:
"""Return the last update as a timestamp."""
return self.balance_date.timestamp()

@property
def inferred_account_type(self) -> AccountType:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
"""Test models."""

from datetime import datetime, timezone

import pytest
from simplefin4py.model import FinancialData


def test_dates(data_200) -> None:
try:
fm: FinancialData = FinancialData.from_json(data_200) # type: ignore
except Exception as e:
pytest.fail(f"Failed to convert JSON data to FinancialData: {e}")

assert fm.accounts[0].balance_date.year == 2024
assert fm.accounts[0].balance_date.month == 1
assert fm.accounts[0].balance_date.day == 16
assert fm.accounts[0].balance_date.hour == 7
assert fm.accounts[0].balance_date.minute == 4
assert fm.accounts[0].balance_date.second == 3
assert fm.accounts[0].balance_date.tzinfo is None
assert fm.accounts[0].last_update.tzinfo == timezone.utc



def test_financial_model(data_200) -> None: # type: ignore
"""Test the financial model parsing."""
try:
Expand Down
Loading