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

Tree @master (Download .tar.gz)

shell_transaction.js @masterraw · history · blame

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

module.exports = {
  q: `from:donotreply@mail.ereceiptshell.com`,
  headers: get_date_header_parser(),
  html: parsers_html_wrapper(function (root) {
    const transaction = {};
    let values_to_match_remaining = 2;
    const tds = root.querySelectorAll('td');
    for (const td of tds) {
      if (td.innerText) {
        if (td.innerText.startsWith('Amount Paid: $')) {
          transaction.value = td.innerText.replace('Amount Paid: $', '') * -1;
          if (--values_to_match_remaining === 0) return transaction;
        } else if (td.innerText.startsWith('Invoice#:')) {
          transaction.description = `Shell Gas ${td.innerText}`;
          if (--values_to_match_remaining === 0) return transaction;
        }
      }
    }
    console.error('Shell parser failed to find all data');
    return transaction;
  })
};