From b7557c5a200ca8f58941d77de86546c7ae617880 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:44:29 -0700 Subject: [PATCH] can read chase balance report --- scrape.go | 6 +- scrape_test.go | 11 +- testdata/chase.2025.balance.txt | 450 ++++++++++++++++++++++++++++++++ 3 files changed, 460 insertions(+), 7 deletions(-) create mode 100644 testdata/chase.2025.balance.txt diff --git a/scrape.go b/scrape.go index ceb46ce..4fdc6c6 100755 --- a/scrape.go +++ b/scrape.go @@ -103,14 +103,16 @@ func (c *chaseScraper) scrape2025Balance(m *mail.Message) ([]*Transaction, error amount := fields[len(fields)-1] amount = strings.TrimLeft(amount, "$") amount = strings.ReplaceAll(amount, ",", "") + amount = fmt.Sprintf("=%s", amount) b, err := ioutil.ReadAll(m.Body) if err != nil { return nil, err } - re = regexp.MustCompile(`>Chase = [^<]*`) - account := strings.TrimPrefix(string(re.Find(b)), ">Chase = ") + re = regexp.MustCompile(`\(\.\.\.([0-9]{4})\)`) + submatches := re.FindSubmatch(b) + account := string(submatches[len(submatches)-1]) return []*Transaction{NewTransaction(account, amount, "*", fmt.Sprint(m.Header["Date"]), Chase)}, nil } diff --git a/scrape_test.go b/scrape_test.go index 841e9f1..833e75d 100644 --- a/scrape_test.go +++ b/scrape_test.go @@ -4,22 +4,23 @@ import ( "bytes" "io/ioutil" "net/mail" + "os" "testing" ) func TestScrapeChase2025Balance(t *testing.T) { + b, _ := os.ReadFile("testdata/chase.2025.balance.txt") + message := &mail.Message{ Header: map[string][]string{ "Subject": []string{"Your Chase Freedom Unlimited balance is $1,029.08"}, }, - Body: bytes.NewReader([]byte(` - TODO - `)), + Body: bytes.NewReader(b), } chase := &chaseScraper{} - gots, err := chase.scrape2025balance(message) + gots, err := chase.scrape2025Balance(message) if err != nil { t.Fatal(err) } @@ -31,7 +32,7 @@ func TestScrapeChase2025Balance(t *testing.T) { if got.Account != "5876" { t.Fatalf("bad account: %v: %+v", got.Account, got) } - if got.Amount != "1029.08" { + if got.Amount != "=1029.08" { t.Fatalf("bad amount: %v: %+v", got.Amount, got) } if got.Vendor != "*" { diff --git a/testdata/chase.2025.balance.txt b/testdata/chase.2025.balance.txt new file mode 100644 index 0000000..3486708 --- /dev/null +++ b/testdata/chase.2025.balance.txt @@ -0,0 +1,450 @@ +Delivered-To: breellocaldev@gmail.com +Received: by 2002:a05:6022:841f:b0:65:30d1:7dd8 with SMTP id cd31csp2448994lab; + Tue, 14 Jan 2025 06:30:20 -0800 (PST) +X-Google-Smtp-Source: AGHT+IHYZt9A+xv7R+D4Y7HTjuMOF9AEKaiIlF4EdjFtsSfmydmud4yvbL76Eu3hDdG3gPzkKq0q +X-Received: by 2002:a05:6102:26c8:b0:4b2:ad82:133a with SMTP id ada2fe7eead31-4b3d0eb943emr21123581137.25.1736865019937; + Tue, 14 Jan 2025 06:30:19 -0800 (PST) +ARC-Seal: i=1; a=rsa-sha256; t=1736865019; cv=none; + d=google.com; s=arc-20240605; + b=Rc1IYtgLaCuSXjmliSBjzCic5e4nKmKGznZ2oE2tH/uDoOMup1O1tttRQlC9cOctpQ + bnab4p6dFpkgMbRJQ5bkUq8hZBufvpTISsrBVrl1QeHuX+IpOCAJSVWAhq/4DlFZYsOg + DJz4bmNsRXBI3/sY5s6F6lBovD5TyJhrxrIOR9BucgdcF1MpggUIa7BUDFjUHMmnRJbl + w9aFWQUzts6j/EbqCrzfcG8VwSqNI+92NacyHUZBQW3FkGFOL6awi+mFWB54aE2pbMfd + gs70fluhGntfisIoN+FLhbSh3tDYJx+s2jradTChgYHSDzbS+d6OLLtlmbQLw8XDwMZU + PzOg== +ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; + h=retry-count:notification-id:content-transfer-encoding:mime-version + :subject:message-id:to:from:date:dkim-signature; + bh=3jCY5JM6cbpoPMj0taKBjFy0yqql6DMNeO04KlgY7p8=; + fh=lrt9myTdNYNEckm/XjduC9YuGfYr3v7r45vYTr/7vKM=; + b=eKMw8xKjUKtT6k6DyEh0UDuPooWFu1Si3rlu8EVh+kAGTUorD+6X8psBD/n15j+msg + +07h4M8xk0FSAMUcRsVENUp9ptnGW6Mt7gBO0CrxdspczNz1ZcKvC61YVevslrqN535F + ndp54648k1fLGbFVQwsRViJkHGne9v8nHw6jYyVC8aU2dwKxTNJBznzgnkyppF6Se1ti + htPjPmc+wVUL0uoz+OhVDCoKhDn+PfyjS5dDdb1kk9EM1WgxW66CrGxGC78pJstZJv9i + tH7ImIDKoyPCRrr57faT+tN5JoA9uR+ANX9jXeFspgyfwuPIXvXzZmfRlwRch4IYp/Vj + Cdlw==; + dara=google.com +ARC-Authentication-Results: i=1; mx.google.com; + dkim=pass header.i=@chase.com header.s=d4815 header.b=Sn1+UmH9; + spf=pass (google.com: domain of no.reply.alerts.14@chase.com designates 146.143.72.23 as permitted sender) smtp.mailfrom=no.reply.alerts.14@chase.com; + dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=chase.com +Return-Path: +Received: from vsin80p3166.jpmchase.com (vsin80p3166.jpmchase.com. [146.143.72.23]) + by mx.google.com with ESMTPS id ada2fe7eead31-4b60929a598si3998057137.312.2025.01.14.06.30.19 + for + (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Tue, 14 Jan 2025 06:30:19 -0800 (PST) +Received-SPF: pass (google.com: domain of no.reply.alerts.14@chase.com designates 146.143.72.23 as permitted sender) client-ip=146.143.72.23; +Authentication-Results: mx.google.com; + dkim=pass header.i=@chase.com header.s=d4815 header.b=Sn1+UmH9; + spf=pass (google.com: domain of no.reply.alerts.14@chase.com designates 146.143.72.23 as permitted sender) smtp.mailfrom=no.reply.alerts.14@chase.com; + dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=chase.com +Received: from pps.filterd (vsin80p3166.dmz.us.jpmchase.net [127.0.0.1]) by vsin80p3166.jpmchase.com (8.18.1.2/8.18.1.2) with ESMTP id 50EDZ96f024767 for ; Tue, 14 Jan 2025 14:30:18 GMT +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chase.com; h=content-transfer-encoding : content-type : date : from : message-id : mime-version : subject : to; s=d4815; bh=3jCY5JM6cbpoPMj0taKBjFy0yqql6DMNeO04KlgY7p8=; b=Sn1+UmH9sAIKrcSjgZt+WYnhb6bWokFKDnKcueoi51YEx1PhxifjbnkH5vC7IxwUTzGA isW1vjStyAi0mF64goItdf4GQBbD2hajG8GhPsDDlssHM5mwLi8Yz07B/p1mrHp8wCqf PRn278RbCw/hP7x2enyrd4WKASn3b/TLQId35h+j8OJk8cDOS/zw2iF/SA7C51hSTcEj Pnm84TIJXer81VZzGC4ReReIpWQbN5Is/A/25h1vLu21Ahb8aIIQ3QHI1D2B2jshpO17 6CzXpxUsBWscUXJWNvrjgqeSlLJW3MPD9bb//uKb+qLr3oGQQ7uD+KOnSG8iqmQPpXHZ lg== +Received: from vsin68p8372.nane.jpmchase.net ([169.103.129.216]) by vsin80p3166.dmz.us.jpmchase.net (PPS) with ESMTPS id 4443sjtnqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jan 2025 14:30:18 +0000 +Received: from iaasn00692074.nane.jpmchase.net (iaasn00692074.nane.jpmchase.net [169.103.127.222]) + by vsin68p8372.nane.jpmchase.net + with ESMTP id 50EEUHGS011857 + for ; Tue, 14 Jan 2025 14:30:17 GMT +Date: Tue, 14 Jan 2025 14:30:17 +0000 (UTC) +From: Chase +To: breellocaldev@gmail.com +Message-ID: <128726875.10629657.1736865017764.JavaMail.webuser@iaasn00692074> +Subject: Your Chase Freedom Unlimited balance is $1,029.08 +MIME-Version: 1.0 +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable +NOTIFICATION-ID: CREDIT_BATCH_BALANCE-28a12d61790b7acb6dc0d2075b17f7c0380224e9a180581da96fa1a87b454084-ver4-31-941c9e20-41c8-3b3c-aefd-f27755b09008 +RETRY-COUNT: 0 + + + + + + + See more details about your card balance. + + + + + + + + + +
+ +
+ + + + +
3D""/ + + + + + + +
+ +
See more details about your card balance.
+ + + +
 ‌ ‌ ‌ ‌ &z= +wnj; ‌ ‌ ‌ ‌ ‌ &zwnj= +; ‌ ‌  ‌ ‌ ‌ &z= +wnj; ‌ ‌ ‌ ‌ ‌ &zwnj= +; ‌ ‌ ‌ ‌ ‌ ‌&n= +bsp;‌ ‌ ‌ ‌ ‌ ‌ = +;‌ ‌ ‌ ‌ ‌ ‌ &z= +wnj; ‌ ‌ ‌ ‌ ‌ &zwnj= +; ‌ ‌ ‌ ‌ ‌ ‌&n= +bsp;‌ ‌ ‌ ‌ ‌ ‌ = +;‌ ‌ ‌ ‌ ‌  ‌&n= +bsp;‌ ‌ ‌ ‌ ‌ ‌ = +;‌ ‌ ‌ ‌ ‌ ‌ &z= +wnj; ‌ ‌ ‌ ‌ ‌ &zwnj= +; ‌ ‌ ‌ ‌ ‌ ‌&n= +bsp;‌ ‌ ‌ ‌ ‌ ‌ = +;‌ ‌ ‌ ‌ ‌ ‌ &z= +wnj; 
+ + + + + + + + +
+ + + +
3D"Chase
+
+ + + +
Account Alert
+ + + +
+ + + + +
3D""Your balance of $1,029.08 is over the level you set
3D""/
+ + + + + + + + + + + + + +
3D""/ + + + + + + + + + + +
+ + + + + + +
+ + + + +
AccountChase = +Freedom Unlimited (...5876)
+ + + + +
Balance$1,029= +.08
You are receiving this alert beca= +use your balance has reached the $0.00 level you set.

You can = +visit our Resource Center anytime to help an= +swer your questions or manage your account.
+
+ + + +
+ + + +
Review account
+
Securely access your accounts wit= +h the Chase Mobile® app or chase.com.
+ + + +
About this message
+
+ Chase Mobile® app is available for s= +elect mobile devices. Message and data rates may apply.
+
+ This service email was sent based on your a= +lert settings. Use the Chase Mobile app or visit chase.com/alerts to view or manage your settings.
+
+ Chase cannot guarantee the delivery of aler= +ts and notifications. Wireless or internet service provider outages or othe= +r circumstances could delay them. You can always check chase.com<= +/span> or the Chase Mobile app for the status of your accounts includi= +ng your latest account balances and transaction details.
+
+ To protect your personal information, pleas= +e don't reply to this message. Chase won't ask for confidential information= + in an email.
+
+ If you have concerns about the authenticity= + of this message or have questions about your account visit chase.c= +om/CustomerService for ways to contact us.
+
+ Your privacy is important to us. See our on= +line Security Center to learn how to protect your i= +nformation.
+
+ © 2025 JPMorgan Chase & Co.
+ 3D""/ + + + + + + + + + + +