AyOK-Code / oscn_scraper

MIT License
1 stars 1 forks source link

Extract amount from description if OSCN adds it after page load #11

Open holdenmitchell opened 2 years ago

holdenmitchell commented 2 years ago

Description

There are times when the amount column in the docket events part of the case page is does not come back with the html, but is loaded after page load via javascript. This logic is captured in the JS below:

//CHECK PAID AMOUNT / TRANSFERS / DISMISSED CASE
    var dockets = document.querySelectorAll(".docketRow");
    var codes = /(account|dismissed)/gi
      , code = "";
    var paid = 0;
    for (var i = 0; i < dockets.length; i++) {
        code = dockets[i].childNodes[3].innerText.match(codes);
        if (!code) {
            continue;
        }
        name = dockets[i].childNodes[9].innerText;
        switch (code[0].toLowerCase()) {
        case 'dismissed':
            //DISMISSED W/COSTS TO STATE
            if (dockets[i].childNodes[5].innerText.match(/costs? to state/gi)) {
                def[name].dismissed += 1;
            }
            break;
        case 'account':
            match = /PAID:\s*?\$\s*?((\d|,)+\.\d+)/gi.exec(dockets[i].childNodes[5].innerText);
            //ACCOUNT PAID
            if (match) {
                amount = parseFloat(match[1].replace(',', ''));
                if (amount == 0.00) {
                    var regex = new RegExp(casenumber + ("\\:\\s*?\\$\\-*?(\\d|\\,)+\\.\\d{2}"),"g")
                    var matches = dockets[i].childNodes[5].innerText.match(regex);
                    if (matches) {
                        matches.forEach(function(m) {
                            amount += parseFloat(m.match(/(\-|\$)?(\d|\,)+\.\d{2}/gi)[0].replace(',', '').replace('$', ''));
                        });
                    }
                }
                if (def[name])
                    def[name].paid += amount;
                //paid += amount;
            }//ACCOUNT ADJUSTED
            else {
                if (dockets[i].childNodes[5].innerText.indexOf("ADJUSTING ENTRY") >= 0) {
                    var regex = new RegExp(casenumber + ("\\:.*?(\\-|\\$)*?(\\d|\\,)+\\.\\d{2}"),"g")
                    var matches = dockets[i].childNodes[5].innerText.match(regex);
                    adjust = 0;
                    if (matches) {
                        matches.forEach(function(m) {
                            adjust += parseFloat(m.match(/(\-|\$)?(\d|\,)+\.\d{2}/gi)[0].replace(",", "").replace("$", ""));
                        });
                        dockets[i].childNodes[11].innerHTML = "<font color='green'>$ -" + adjust.toFixed(2) + "</font>";
                    }
                }
            }
            break;
        default:
            break;
        }
    }