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

Tree @master (Download .tar.gz)

aep.js @masterraw · history · blame

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

module.exports = {
  q: `from:communications@aep-email.com subject:"Your AEP Ohio bill is available"`,
  headers: get_date_header_parser('created_date'),
  html: parsers_html_wrapper(function (root) {
    const transaction = {};
    const ps = root.querySelectorAll('p');
    for (const p of ps) {
      if (p.innerText) {
        if (p.innerText.startsWith('Your payment of')) {
          let [value, date] = p.innerText.split(/\s/).join('').replace('Yourpaymentof$', '').split('willbeautomaticallywithdrawnon')
          if (date.endsWith('.')) {
            date = date.substring(0, date.length - 1);
          }
          return {
            value: value.replace(',', '') * -1,
            date: time.iso(time.now(date, 'M/D/YYYY'))
          }
        }
      }
    }
    console.error('AEP parser failed to find all data');
    return transaction;
  })
};