From 1f765a50357fc2cfe9e5fa635453c353e5738df9 Mon Sep 17 00:00:00 2001 From: Mendel E Date: Wed, 8 Jun 2022 06:22:22 -0400 Subject: [PATCH] Add chase parser --- parser/all/all.go | 1 + parser/chase/interface.go | 44 +++++++++++++++++++++++++++++++++++++++ parser/chase/parser.go | 39 ++++++++++++++++++++++++++++++++++ parser/chase/types.go | 23 ++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 parser/chase/interface.go create mode 100644 parser/chase/parser.go create mode 100644 parser/chase/types.go diff --git a/parser/all/all.go b/parser/all/all.go index bb6010f..455702b 100644 --- a/parser/all/all.go +++ b/parser/all/all.go @@ -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" ) diff --git a/parser/chase/interface.go b/parser/chase/interface.go new file mode 100644 index 0000000..9f539ff --- /dev/null +++ b/parser/chase/interface.go @@ -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, " ") +} diff --git a/parser/chase/parser.go b/parser/chase/parser.go new file mode 100644 index 0000000..be2118f --- /dev/null +++ b/parser/chase/parser.go @@ -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" +} diff --git a/parser/chase/types.go b/parser/chase/types.go new file mode 100644 index 0000000..51db463 --- /dev/null +++ b/parser/chase/types.go @@ -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"` +} -- 2.34.4