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

Tree @master (Download .tar.gz)

columbia_gas.js @masterraw · history · blame

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

module.exports = {
  q: `from:myaccount@columbiagasohio.com subject:"Columbia Gas of Ohio Bill Ready"`,
  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) {
        const text = p.innerText.trim();
        if (text.startsWith('Current Charges Due')) {
          transaction.value = text.split(':')[1].trim().replace('$', '').replace(',', '') * -1;
          if (--values_to_match_remaining === 0) return transaction;
        } else if (text.startsWith('AutoPay Withdraw on')) {
          transaction.date = time.iso(time.now(text.split(':')[1].trim(), 'MM/DD/YYYY'));
          if (--values_to_match_remaining === 0) return transaction;
        }
      }
    }
    console.error('Columbia Gas parser failed to find all data');
    return transaction;
  })
};