add anti-patterns, print acc for ledger, fix chase 2021 from body.read double
parent
24b66d1c46
commit
3077343c89
|
|
@ -35,6 +35,7 @@ type Config struct {
|
|||
Storage storage.DB
|
||||
Banks map[Bank]bool
|
||||
AccountsPattern string
|
||||
AccountsAntiPattern string
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
|
@ -55,7 +56,8 @@ func NewConfig() Config {
|
|||
as.Append(args.STRING, "todotag", "todo tag", "expense")
|
||||
|
||||
as.Append(args.STRING, "banks", "uccu,citi,chase", "uccu,citi,chase")
|
||||
as.Append(args.STRING, "accounts", "regex to filter accounts", ".*")
|
||||
as.Append(args.STRING, "accounts", "regex to include filter accounts", ".*")
|
||||
as.Append(args.STRING, "not-accounts", "regex to exclude filter accounts", "zzzzzz")
|
||||
|
||||
as.Append(args.STRING, "authaddr", "auth addr", "https://auth.remote.blapointe.com")
|
||||
as.Append(args.STRING, "store", "store type", "map")
|
||||
|
|
@ -85,6 +87,7 @@ func NewConfig() Config {
|
|||
TodoAddr: as.GetString("todoaddr"),
|
||||
TodoTag: as.GetString("todotag"),
|
||||
AccountsPattern: as.GetString("accounts"),
|
||||
AccountsAntiPattern: as.GetString("not-accounts"),
|
||||
Storage: storage,
|
||||
Uploader: ul,
|
||||
Banks: map[Bank]bool{
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -18,6 +18,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
patterns := regexp.MustCompile(config.AccountsPattern)
|
||||
antipatterns := regexp.MustCompile(config.AccountsAntiPattern)
|
||||
for email := range emails {
|
||||
transactions, err := Scrape(email, config.Banks)
|
||||
if err != nil {
|
||||
|
|
@ -26,6 +27,11 @@ func main() {
|
|||
for _, transaction := range transactions {
|
||||
if !patterns.MatchString(transaction.Account) {
|
||||
log.Printf("skipping unmatching account pattern %q vs %q", config.AccountsPattern, transaction.Account)
|
||||
continue
|
||||
}
|
||||
if antipatterns.MatchString(transaction.Account) {
|
||||
log.Printf("skipping match account antipattern %q vs %q", config.AccountsAntiPattern, transaction.Account)
|
||||
continue
|
||||
}
|
||||
if _, err := config.Storage.Get(transaction.ID); err == nil {
|
||||
log.Println("skipping duplicate transaction:", transaction)
|
||||
|
|
|
|||
|
|
@ -67,11 +67,11 @@ func containsAny(a string, b ...string) bool {
|
|||
}
|
||||
|
||||
func (c *chaseScraper) scrape(m *mail.Message) ([]*Transaction, error) {
|
||||
transactions, err := c.scrape2020(m)
|
||||
transactions, err := c.scrape2021(m)
|
||||
if err == nil && len(transactions) > 0 {
|
||||
return transactions, err
|
||||
}
|
||||
return c.scrape2021(m)
|
||||
return c.scrape2020(m)
|
||||
}
|
||||
|
||||
func (c *chaseScraper) scrape2021(m *mail.Message) ([]*Transaction, error) {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func uploadLedger(config Config, transaction *Transaction) error {
|
|||
remote += substr
|
||||
}
|
||||
fmt.Fprintf(f, "%-50s%-s\n", formatGMailDate(transaction.Date), transaction.Vendor)
|
||||
fmt.Fprintf(f, "%-50s%-50s$%.2f\n", "", "AssetAccount:"+transaction.Bank.String(), amount)
|
||||
fmt.Fprintf(f, "%-50s%-50s$%.2f\n", "", "AssetAccount:"+transaction.Bank.String()+":"+transaction.Account, amount)
|
||||
fmt.Fprintf(f, "%-50s%-s\n", "", remote)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue