From f6fc366dd4d231364078a8462b53e8f360495d9b Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 9 Dec 2022 08:52:36 -0700 Subject: [PATCH] stub wip fidelity --- bank.go | 3 ++ config.go | 3 ++ main.go | 1 + scrape.go | 12 ++++++++ scrape_test.go | 35 +++++++++++++++++++++++ testdata/fidelity.withdrawal.txt | 49 ++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+) create mode 100644 testdata/fidelity.withdrawal.txt diff --git a/bank.go b/bank.go index 738f8d3..5841c76 100755 --- a/bank.go +++ b/bank.go @@ -7,10 +7,13 @@ const ( Citi Bank = iota + 1 UCCU Bank = iota + 1 BankOfAmerica Bank = iota + 1 + Fidelity Bank = iota + 1 ) func (b Bank) String() string { switch b { + case Fidelity: + return "Fidelity" case BankOfAmerica: return "BankOfAmerica" case Chase: diff --git a/config.go b/config.go index 73186ed..0e8a03b 100755 --- a/config.go +++ b/config.go @@ -30,6 +30,7 @@ type Config struct { EmailUser string EmailPass string EmailIMAP string + EmailLimit int TodoAddr string TodoToken string TodoList string @@ -49,6 +50,7 @@ func NewConfig() Config { as.Append(args.STRING, "emailuser", "email username", "breellocaldev@gmail.com") as.Append(args.STRING, "emailpass", "email password", "diblloewfncwssof") as.Append(args.STRING, "emailimap", "email imap", "imap.gmail.com:993") + as.Append(args.INT, "emaillimit", "email limit", 0) as.Append(args.STRING, "uploader", "todo, ledger, pttodo", "todo") @@ -87,6 +89,7 @@ func NewConfig() Config { EmailUser: as.GetString("emailuser"), EmailPass: as.GetString("emailpass"), EmailIMAP: as.GetString("emailimap"), + EmailLimit: as.GetInt("emaillimit"), TodoAddr: as.GetString("todoaddr"), TodoTag: as.GetString("todotag"), AccountsPattern: as.GetString("accounts"), diff --git a/main.go b/main.go index 6e7ad3d..5c032dc 100755 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ func main() { IMAP: config.EmailIMAP, From: config.EmailUser, Password: config.EmailPass, + Limit: config.EmailLimit, } emails, err := emailer.Read() if err != nil { diff --git a/scrape.go b/scrape.go index 12a8610..f36b45a 100755 --- a/scrape.go +++ b/scrape.go @@ -15,6 +15,7 @@ type scraper interface { scrape(*mail.Message) ([]*Transaction, error) } +type fidelityScraper struct{} type bankOfAmericaScraper struct{} type chaseScraper struct{} type citiScraper struct{} @@ -37,6 +38,9 @@ func buildScraper(m *mail.Message, banks map[Bank]bool) (scraper, error) { if strings.Contains(from, "Chase") && banks[Chase] { return newChaseScraper(), nil } + if strings.Contains(from, "Fidelity") && banks[Fidelity] { + return newFidelityScraper(), nil + } if strings.Contains(from, "Bank of America") && banks[BankOfAmerica] { return newBankOfAmericaScraper(), nil } @@ -49,6 +53,10 @@ func buildScraper(m *mail.Message, banks map[Bank]bool) (scraper, error) { return nil, errors.New("unknown sender: " + from) } +func newFidelityScraper() scraper { + return &fidelityScraper{} +} + func newBankOfAmericaScraper() scraper { return &bankOfAmericaScraper{} } @@ -210,6 +218,10 @@ func (c *uccuScraper) scrape(m *mail.Message) ([]*Transaction, error) { return []*Transaction{transaction}, nil } +func (c *fidelityScraper) scrape(m *mail.Message) ([]*Transaction, error) { + panic(nil) +} + func (c *bankOfAmericaScraper) scrape(m *mail.Message) ([]*Transaction, error) { subject := fmt.Sprint(m.Header["Subject"]) if strings.Contains(subject, "Credit card transaction") { diff --git a/scrape_test.go b/scrape_test.go index ef7a43c..1e334e9 100644 --- a/scrape_test.go +++ b/scrape_test.go @@ -179,6 +179,41 @@ func TestScrapeBofAPayment(t *testing.T) { } } +func TestScrapeFidelityWithdrawal(t *testing.T) { + b, err := ioutil.ReadFile("./testdata/fidelity.withdrawal.txt") + if err != nil { + t.Fatal(err) + } + message := &mail.Message{ + Header: map[string][]string{ + "Subject": []string{"Credit card transaction exceeds alert limit you set"}, + }, + Body: bytes.NewReader(b), + } + bofa := &bankOfAmericaScraper{} + + gots, err := bofa.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: BankOfAmerica, + Amount: "75.08", + Vendor: "PAYPAL GIBBDOGENTE MA", + Date: "[]", + Account: BankOfAmerica.String(), + } + if *got != want { + t.Fatalf("want:\n\t%+v, got\n\t%+v", want, *got) + } +} + func TestScrapeBofACharge(t *testing.T) { b, err := ioutil.ReadFile("./testdata/bofa.charge.txt") if err != nil { diff --git a/testdata/fidelity.withdrawal.txt b/testdata/fidelity.withdrawal.txt new file mode 100644 index 0000000..bb61748 --- /dev/null +++ b/testdata/fidelity.withdrawal.txt @@ -0,0 +1,49 @@ + +For account ending in 5576: +Money was withdrawn from your account through a direct debit in the amount of $1.00 by CHASE CREDIT CRD. + +If you authorized this transaction, no action is needed. + If you did not authorize this transaction, please contact us immediately at 800-343-3548. + + + +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://alertable.fidelity.com/alerts/help/agreement.html. If you would +prefer to not receive these alerts, please change your preferences at +https://scs.fidelity.com/customeronly/alerts.shtml. +This new alerts service will not affect delivery of paper communications +you are scheduled to receive. + +To stop receipt of alerts, modify your preferences on the Existing Alerts page +at https://scs.fidelity.com/customeronly/fens.shtml, or temporarily +stop/restart alerts at +https://scs.fidelity.com/customeronly/fens_alertstatus.shtml. + +Fidelity offers access to a broader range of third-party research at +http://personal.fidelity.com/research/stocks/content/stocksindex.shtml. +Fidelity is not recommending or endorsing any third-party research by making it +available to its customers or by notifying customers of its availability. + +Review Fidelity's Terms of Use for Third Party Content and Research at +http://activequote.fidelity.com/rtrnews/terms.html. + +If your email has changed, please update your email address +at https://scs.fidelity.com/customeronly/fens_profile.shtml to continue to +receive your alerts. + +Read Fidelity's Commitment to Privacy +at http://personal.fidelity.com/global/search/content/privacy.html.tvsr. + +Visit Fidelity's Home Page +http://www.fidelity.com/ + +Fidelity Brokerage Services LLC, Member NYSE, SIPC, 900 Salem Street, Smithfield, RI 02917 + +EMAIL REF# 537048 + +Copyright 2022 FMR LLC +All rights reserved. Important Legal Information +at http://personal.fidelity.com/misc/legal/legal.html.tvsr. +