-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcash_app.go
65 lines (53 loc) · 1.71 KB
/
cash_app.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package goldmachine
import (
"regexp"
"strconv"
"strings"
"time"
"github.com/Rhymond/go-money"
)
func ParseCashAppCSV(in string) ([]JournalEntry, error) {
cashAppHeader := regexp.MustCompile(`Transaction ID`)
cashAppPatterns := ps(
p("🧼|✨|🧹", HOME),
)
return convertToJournalEntries(in, func(line []string) (JournalEntry, error) {
//"Transaction ID","Name","Notes","Date","Status","Account","Amount","Fee","Net Amount","Currency"
//"f69na6n","'Winderson'","'🧼'","2019-06-20 09:19:02 PDT","PAYMENT SENT","Visa Debit 3167","-$140","$0","-$140","USD"
je := &JournalEntry{}
if cashAppHeader.MatchString(line[0]) {
return *je, Skip
}
stamp, err := time.Parse("2006-01-02 15:04:05 MST", line[3])
if err != nil {
return *je, err
}
je.EffectiveAt = stamp
je.Identifier = line[1] + " " + line[2] // identifier is also the payee
if line[5] != "Your Cash" {
return *je, Skip
}
amountString := strings.Replace(strings.Replace(strings.Replace(line[8], "$", "", -1), "+", "", -1), " ", "", -1)
if amountString == "" {
return *je, Skip
}
amountFloat, err := strconv.ParseFloat(amountString, 64)
if err != nil {
return *je, err
}
amount := money.New(int64(amountFloat*100), line[9])
if amountFloat == 0 {
return *je, Skip
}
if amountFloat < 0 {
var account Account
account = accountFromPatterns(line[5], cashAppPatterns)
je.AddEntry(NewCreditEntry(amount.Absolute(), CASH_APP, line[5]))
je.AddEntry(NewDebitEntry(amount.Absolute(), account, line[5]))
} else {
je.AddEntry(NewCreditEntry(amount.Absolute(), accountFromPatterns(line[5], cashAppPatterns), line[5]))
je.AddEntry(NewDebitEntry(amount.Absolute(), CASH_APP, line[5]))
}
return *je, nil
})
}