~mendelmaleh/pfin

1f765a50357fc2cfe9e5fa635453c353e5738df9 — Mendel E 11 months ago 6b408c9
Add chase parser
4 files changed, 107 insertions(+), 0 deletions(-)

M parser/all/all.go
A parser/chase/interface.go
A parser/chase/parser.go
A parser/chase/types.go
M parser/all/all.go => parser/all/all.go +1 -0
@@ 4,5 4,6 @@ import (
	_ "git.sr.ht/~mendelmaleh/pfin/parser/amex"
	_ "git.sr.ht/~mendelmaleh/pfin/parser/bofa"
	_ "git.sr.ht/~mendelmaleh/pfin/parser/capitalone"
	_ "git.sr.ht/~mendelmaleh/pfin/parser/chase"
	_ "git.sr.ht/~mendelmaleh/pfin/parser/personal"
)

A parser/chase/interface.go => parser/chase/interface.go +44 -0
@@ 0,0 1,44 @@
package chase

import (
	"time"

	"git.sr.ht/~mendelmaleh/pfin"
	"git.sr.ht/~mendelmaleh/pfin/util"
)

var _ = pfin.Transaction(Transaction{})

func (tx Transaction) Date() time.Time {
	return tx.Raw.TransactionDate.Time
}

func (tx Transaction) Amount() float64 {
	return tx.Raw.Amount
}

func (tx Transaction) Name() string {
	return tx.Raw.Description
}

func (tx Transaction) Category() string {
	return tx.Raw.Category
}

// not implemented
func (tx Transaction) Card() string {
	return ""
}

func (tx Transaction) User() string {
	return tx.Fields.User
}

func (tx Transaction) Account() string {
	return tx.Fields.Account
}

// should be util.FormatTx
func (tx Transaction) String() string {
	return util.FormatTx(tx, " ")
}

A parser/chase/parser.go => parser/chase/parser.go +39 -0
@@ 0,0 1,39 @@
package chase

import (
	"git.sr.ht/~mendelmaleh/pfin"
	"github.com/jszwec/csvutil"
)

func init() {
	pfin.Register("chase", Parser{})
}

type Parser struct{}

func (Parser) Parse(acc pfin.Account, filename string, data []byte) (txns []pfin.Transaction, err error) {
	var raw []Transaction
	if err = csvutil.Unmarshal(data, &raw); err != nil {
		return
	}

	length := len(raw)
	txns = make([]pfin.Transaction, length)

	// reverse order
	for i := 0; i < length; i++ {
		v := raw[length-i-1]

		// default user
		v.Fields.User = acc.User("")
		v.Fields.Account = acc.Name

		txns[i] = v
	}

	return
}

func (Parser) Filetype() string {
	return "csv"
}

A parser/chase/types.go => parser/chase/types.go +23 -0
@@ 0,0 1,23 @@
package chase

import "git.sr.ht/~mendelmaleh/pfin/parser/util"

type Transaction struct {
	Fields
	Raw
}

type Fields struct {
	User    string
	Account string
}

type Raw struct {
	TransactionDate util.DateUS `csv:"Transaction Date"`
	PostDate        util.DateUS `csv:"Post Date"`
	Description     string      `csv:"Description"`
	Category        string      `csv:"Category"`
	Type            string      `csv:"Type"`
	Amount          float64     `csv:"Amount"`
	Memo            string      `csv:"Memo"`
}