impl fidel deposit
parent
8b226294a2
commit
5c557ea713
21
scrape.go
21
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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue