127.0.0.1:8000 budget / master server / external_apis / gmail / email_parsers / 53_mortgage.js
master

Tree @master (Download .tar.gz)

53_mortgage.js @masterraw · history · blame

const {
  get_date_header_parser,
  parsers_html_wrapper
} = require('./helpers');
const time = require('../../../utils/time');

module.exports = {
  q: `from:FifthThirdBank@53.com subject:"Payment Due Soon"`,
  headers: get_date_header_parser('created_date'),
  html: parsers_html_wrapper(function (root) {
    const transaction = {};

    let values_to_match_remaining = 2;

    const ps = root.querySelectorAll('p');
    for (const p of ps) {
      if (p.innerText) {
        if (p.innerText.startsWith('Monthly Amount Due')) {
          transaction.value = p.innerText.split(':')[1].trim().replace('$', '').replace(',', '') * -1;
          if (--values_to_match_remaining === 0) return transaction;
        } else if (p.innerText.startsWith('Payment Due Date')) {
          transaction.date = time.iso(time.now(p.innerText, 'MM/DD'));
          if (--values_to_match_remaining === 0) return transaction;
        }
      }
    }
    console.error('5/3 Mortgage parser failed to find all data');
    return transaction;
  })
};