flexible encoding when reading comdirect data
This commit is contained in:
+13
-4
@@ -5,7 +5,6 @@ from pathlib import Path
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from settings import BANK_ACCOUNTS
|
||||
from src.db import get_session
|
||||
from src.ingest._common import _upsert
|
||||
from src.models._common import Csv2Dict, CsV2DictMulti
|
||||
from src.models.comdirect import (
|
||||
@@ -52,10 +51,18 @@ def reader_comdirect(path: Path) -> dict[str, list[ComdirectExportModel]]:
|
||||
return result
|
||||
|
||||
|
||||
def _open_and_readlines(path: Path, encoding: str) -> list:
|
||||
with path.open("r", encoding=encoding) as fid:
|
||||
lines = fid.readlines()
|
||||
return lines
|
||||
|
||||
|
||||
def _reader_raw_comdirect(path: Path) -> CsV2DictMulti:
|
||||
|
||||
with path.open("r", encoding="utf-8") as fid:
|
||||
lines = fid.readlines()
|
||||
try:
|
||||
lines = _open_and_readlines(path, encoding="utf-8")
|
||||
except UnicodeDecodeError:
|
||||
lines = _open_and_readlines(path, encoding="latin-1")
|
||||
|
||||
expect_next = EXPECT_LINE.ACCOUNT_NAME
|
||||
account_name = None
|
||||
@@ -123,7 +130,9 @@ def upsert_comdirect_giro(
|
||||
)
|
||||
|
||||
|
||||
def ingest_comdirect(session: Session, path: Path, account_iban: str, account_currency: str):
|
||||
def ingest_comdirect(
|
||||
session: Session, path: Path, account_iban: str, account_currency: str
|
||||
):
|
||||
assert SOURCE_COMDIRECT
|
||||
data_collection = reader_comdirect(path)
|
||||
for account_name, data in data_collection.items():
|
||||
|
||||
Reference in New Issue
Block a user