There is now the possibility to download the transactions for all banks in the banks table in the DB. `NordigenInput` parse method fully functional, and entire chain from downloading to parsing (simple w/ converter) to writing to DB. DbTransaction type added __conform__ to simplify writes to DB. Get bank methods added to both `Manager` and `DatabaseClient`. Warning: csv parser most likely not working at this point. Issues #16 and #17
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import json
|
|
|
|
from .input import Input
|
|
from pfbudget.common.types import Transactions
|
|
from pfbudget.utils import convert, parse_decimal
|
|
|
|
|
|
class JsonParser(Input):
|
|
def __init__(self, manager, options):
|
|
super().__init__(manager)
|
|
self.options = options
|
|
|
|
def parse(self) -> Transactions:
|
|
try:
|
|
with open(self.options["json"][0], "r") as f:
|
|
return [
|
|
convert(
|
|
[
|
|
t["bookingDate"],
|
|
t["remittanceInformationUnstructured"],
|
|
self.options["bank"][0],
|
|
parse_decimal(t["transactionAmount"]["amount"])
|
|
if not self.options["invert"]
|
|
else -parse_decimal(t["transactionAmount"]["amount"]),
|
|
],
|
|
)
|
|
for t in json.load(f)["transactions"]["booked"]
|
|
]
|
|
except KeyError:
|
|
print("No json file defined")
|