From 5c557ea713b1c97ef931183e8fa7c800a8a97a67 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 9 Dec 2022 09:52:22 -0700 Subject: [PATCH] impl fidel deposit --- scrape.go | 21 +++++++++++++++++++++ scrape_test.go | 35 +++++++++++++++++++++++++++++++++++ testdata/fidelity.deposit.txt | 29 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 testdata/fidelity.deposit.txt diff --git a/scrape.go b/scrape.go index 00d0962..6fe22d9 100755 --- a/scrape.go +++ b/scrape.go @@ -223,9 +223,30 @@ func (c *fidelityScraper) scrape(m *mail.Message) ([]*Transaction, error) { if strings.Contains(subject, "Debit Withdrawal") { return c.scrapeWithdrawal(m) } + if strings.Contains(subject, "Deposit Received") { + return c.scrapeDeposit(m) + } panic(nil) } +func (c *fidelityScraper) scrapeDeposit(m *mail.Message) ([]*Transaction, error) { + b, err := ioutil.ReadAll(m.Body) + if err != nil { + return nil, err + } + + fidelAcc, _ := findSubstringBetween(b, "Account: XXXXX", "\n") + + transaction := NewTransaction( + fmt.Sprintf("%s-%s", Fidelity, fidelAcc), + "?.??", + "misc", + fmt.Sprint(m.Header["Date"]), + Fidelity, + ) + return []*Transaction{transaction}, nil +} + func (c *fidelityScraper) scrapeWithdrawal(m *mail.Message) ([]*Transaction, error) { b, err := ioutil.ReadAll(m.Body) if err != nil { diff --git a/scrape_test.go b/scrape_test.go index b8d1963..5667531 100644 --- a/scrape_test.go +++ b/scrape_test.go @@ -179,6 +179,41 @@ func TestScrapeBofAPayment(t *testing.T) { } } +func TestScrapeFidelityDeposit(t *testing.T) { + b, err := ioutil.ReadFile("./testdata/fidelity.deposit.txt") + if err != nil { + t.Fatal(err) + } + message := &mail.Message{ + Header: map[string][]string{ + "Subject": []string{"Fidelity Alerts: Deposit Received"}, + }, + Body: bytes.NewReader(b), + } + fidelity := &fidelityScraper{} + + gots, err := fidelity.scrape(message) + if err != nil { + t.Fatal(err) + } + + if len(gots) != 1 { + t.Fatal(len(gots)) + } + got := gots[0] + want := Transaction{ + ID: got.ID, + Bank: Fidelity, + Amount: "?.??", + Vendor: "misc", + Date: "[]", + Account: Fidelity.String() + "-5576", + } + if *got != want { + t.Fatalf("want:\n\t%+v, got\n\t%+v", want, *got) + } +} + func TestScrapeFidelityWithdrawal(t *testing.T) { b, err := ioutil.ReadFile("./testdata/fidelity.withdrawal.txt") if err != nil { diff --git a/testdata/fidelity.deposit.txt b/testdata/fidelity.deposit.txt new file mode 100644 index 0000000..fbb6772 --- /dev/null +++ b/testdata/fidelity.deposit.txt @@ -0,0 +1,29 @@ + +Account: XXXXX5576 + +A deposit to your account was received on 12/08/2022. + + + +Important information: +Fidelity automatically emails certain alerts to customers who have provided +an email address. You can see the terms which govern these alerts at +https://www.fidelity.com/customer-service/alerts-agreement. If you would +prefer to not receive these alerts, please change your preferences at +https://scs.fidelity.com/customeronly/alerts.shtml. + +Review Fidelity's Terms of Use for Third Party Content and Research at +https://www.fidelity.com/terms-of-use#Third. + +If your email has changed, please update your email address +at https://alertable.fidelity.com/ftgw/alerts/GetUserDeliveryDevices to continue to +receive your alerts. + +Fidelity Brokerage Services LLC, Member NYSE, SIPC + +EMAIL REF# 537048 + +Copyright 2022 FMR LLC +All rights reserved. Important Legal Information +at http://www.fidelity.com/terms-of-use. +