Finish the loader.

This commit is contained in:
Dominik Pantůček 2023-03-30 13:49:05 +02:00
parent 71e016a3aa
commit b86360904f
2 changed files with 31 additions and 4 deletions

View file

@ -43,8 +43,11 @@
;; Bank account is represented as a list with list with the following
;; elements: list of transactions, account number, bank code. This
;; allows cheap transaction prepending.
(define (make-bank-account number bank)
(list '() number bank))
(define (make-bank-account number bank . maybe-transactions)
(let ((transactions (if (null? maybe-transactions)
'()
(car maybe-transactions))))
(list transactions number bank)))
;; Prepends given transaction to given bank account. It expects the
;; transactions list to be the first element of the bank account

View file

@ -32,11 +32,35 @@
)
(import scheme
(chicken base)
(chicken irregex)
bank-account
csv-simple)
;; Converts Fio account statement transaction row into standardized
;; bank transaction structure.
(define (make-fio-transaction row)
(let ((id (string->number (car row)))
(date (cadr row))
(amount (string->number
(irregex-replace (irregex "," 'u)
(caddr row)
".")))
(currency (cadddr row))
(varsym (list-ref row 9)))
(make-bank-transaction id date amount currency varsym)))
;; Loads Fio bank accound statement.
(define (bank-fio-parse fn)
(let ((csv (csv-parse fn)))
#f))
(let* ((csv (csv-parse fn))
(head+body (csv-split-header csv))
(head (car head+body))
(body (cadr head+body))
(numrow (assoc "accountId" head))
(num (if numrow (cadr numrow) "ERROR"))
(bankrow (assoc "bankId" head))
(bank (if bankrow (cadr bankrow) "ERROR")))
(make-bank-account num bank
(map make-fio-transaction body))))
)