~mendelmaleh/pfin

ref: 1f765a50357fc2cfe9e5fa635453c353e5738df9 pfin/parser/amex/parser.go -rw-r--r-- 659 bytes
1f765a50Mendel E Add chase parser 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package amex

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

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

type Parser struct{}

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

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 so it's chronological
	for i := 0; i < length; i++ {
		v := raw[length-i-1]

		v.Fields.User = acc.User(v.Card())
		v.Fields.Account = acc.Name

		txns[i] = v
	}

	return
}