Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This **does not use Selenium** or headless browsers, or Amazon sign-in, which is

## Environment variables

Please store your email credentials in environment variables or through a `.env` file.
Please store your email credentials in environment variables or through a `.env` file.

```
```env
IMAP_USERNAME=email@domain.com
IMAP_PASSWORD=p@ssw0rd123!
IMAP_INCOMING_HOST=imap.domain.com
Expand Down Expand Up @@ -50,4 +50,4 @@ It looks for matching transactions with blank memo's. If you don't like the memo

## Cache

This is a stateless application, and uses no database. Everything exists in memory. It will cache YNAB transactions on start, and then only properly request new transactions through the API. If you decide to run this as a service, please introduce a restart count limit so that you don't spam YNAB API if there's a fatal bug and the application keeps restarting.
This is a stateless application, and uses no database. Everything exists in memory. It will cache YNAB transactions on start, and then only properly request new transactions through the API. If you decide to run this as a service, please introduce a restart count limit so that you don't spam YNAB API if there's a fatal bug and the application keeps restarting.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "dotenv/config";
import IMAP from "node-imap";
import YNAB from "./ynab.js";
import { historicalSearch, watchInbox } from "./mail.js";
import YNAB from "./ynab.js";

const INBOX_NAME = process.env.IMAP_INBOX_NAME || "INBOX";

Expand Down
14 changes: 10 additions & 4 deletions mail.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IMAP from "node-imap";
import * as cheerio from "cheerio";
import IMAP from "node-imap";
import quotedPrintable from "quoted-printable";
import { dateFormat, dollarFormat } from "./index.js";

Expand Down Expand Up @@ -28,7 +28,12 @@ const scanEmail = (email) => {

try {
const amount = parseFloat(
$('table[id$="costBreakdownRight"] td').text().trim().slice(1)
$('td:contains("Order Total:")')
.next("td")
.find("span")
.text()
.trim()
.slice(1)
);

if (amount === 0) return;
Expand Down Expand Up @@ -163,8 +168,8 @@ export const historicalSearch = async (imap, ynab, box, orders) =>
const email = await readEmail(imapMsg, false);
if (isAmazonEmail(email)) amazonMsgSeqNums.push(seqno);
processedEmails++;
console.log(
`${processedEmails} emails collected... Limit: ${HISTORICAL_SEARCH_NUM_EMAILS}`
process.stdout.write(
`\r${processedEmails} emails collected... Limit: ${HISTORICAL_SEARCH_NUM_EMAILS}`
);
resolve();
} catch (e) {
Expand All @@ -181,6 +186,7 @@ export const historicalSearch = async (imap, ynab, box, orders) =>

fetch.once("end", async () => {
await Promise.allSettled(emailFetches);
process.stdout.write("\n");

const amazonEmailCount = amazonMsgSeqNums.length;
console.info(
Expand Down
Loading