src/cttTracker.js
function createCttEntity(id, html, cb) {

    let state = null
    let messages = []

    try {
        html = htmlBeautify(html)
        let $ = parser.load(html)

        let table = $('table.full-width tr').get(1).children.filter(e => e.type == 'tag')

        let dayAndHours = table[2].children[0].data.trim() + ' ' + table[3].children[0].data.trim()
        state = {
            date: moment.tz(dayAndHours, "YYYY/MM/DD HH:mm", zone).format()
        }

        if(table[4].children.length == 0) {
            state['status'] = 'Sem estado'
        } else {
            if(table[4].children[0].data) {
                state['status'] = table[4].children[0].data.trim()
            } else {
                state['status'] = table[4].children[0].children[0].data.trim()
            }
        }

        let details = $('#details_0').find('tr')

        let day = ""
        let dayUnformated = ""
        let message = {}
        for(let i = 0; i < details.length; i++) {
            let tr = details.get(i)
            if(tr.children.length >= 8){
                let idxsum = 0

                if(tr.children.length >= 9) {
                    day = tr.children[0].children[0].data.trim()
                    dayUnformated = day.split(',')[1].trim()
                    day = moment.tz(dayUnformated, "DD MMMM YYYY", 'pt', zone).format()
                    message = {
                        day: day,
                        status: []
                    }
                    messages.push(message)
                    idxsum = 1
                }

                let hours = tr.children[0+idxsum].children[0].data.trim()
                let time = moment.tz(dayUnformated + ' ' + hours, "DD MMMM YYYY HH:mm", 'pt', zone).format()
                let add = {
                    time: time,
                    status: tr.children[2+idxsum].children[0].data.trim(),
                    local: tr.children[6+idxsum].children[0].data.trim()
                }
                message.status.push(add)
            }
        }

    } catch (error) {
        return cb(error)
    }

    cb(null, new CttInfo(id, state, messages))

}
function createCttEntity(id, html, cb) {

    let state = null
    let messages = []

    try {
        html = htmlBeautify(html)
        let $ = parser.load(html)

        let table = $('table.full-width tr').get(1).children.filter(e => e.type == 'tag')

        let dayAndHours = table[2].children[0].data.trim() + ' ' + table[3].children[0].data.trim()
        state = {
            date: moment.tz(dayAndHours, "YYYY/MM/DD HH:mm", zone).format()
        }

        if(table[4].children.length == 0) {
            state['status'] = 'Sem estado'
        } else {
            if(table[4].children[0].data) {
                state['status'] = table[4].children[0].data.trim()
            } else {
                state['status'] = table[4].children[0].children[0].data.trim()
            }
        }

        let details = $('#details_0').find('tr')

        let day = ""
        let dayUnformated = ""
        let message = {}
        for(let i = 0; i < details.length; i++) {
            let tr = details.get(i)
            if(tr.children.length >= 8){
                let idxsum = 0

                if(tr.children.length >= 9) {
                    day = tr.children[0].children[0].data.trim()
                    dayUnformated = day.split(',')[1].trim()
                    day = moment.tz(dayUnformated, "DD MMMM YYYY", 'pt', zone).format()
                    message = {
                        day: day,
                        status: []
                    }
                    messages.push(message)
                    idxsum = 1
                }

                let hours = tr.children[0+idxsum].children[0].data.trim()
                let time = moment.tz(dayUnformated + ' ' + hours, "DD MMMM YYYY HH:mm", 'pt', zone).format()
                let add = {
                    time: time,
                    status: tr.children[2+idxsum].children[0].data.trim(),
                    local: tr.children[6+idxsum].children[0].data.trim()
                }
                message.status.push(add)
            }
        }

    } catch (error) {
        return cb(error)
    }

    cb(null, new CttInfo(id, state, messages))

}
function createCttEntity ( id , html , cb ) { let state = null let messages = [ ] try { html = htmlBeautify ( html ) let $ = parser . load ( html ) let table = $ ( 'table.full-width tr' ) . get ( 1 ) . children . filter ( e => e . type == 'tag' ) let dayAndHours = table [ 2 ] . children [ 0 ] . data . trim ( ) + ' ' + table [ 3 ] . children [ 0 ] . data . trim ( ) state = { date : moment . tz ( dayAndHours , "YYYY/MM/DD HH:mm" , zone ) . format ( ) } if ( table [ 4 ] . children . length == 0 ) { state [ 'status' ] = 'Sem estado' } else { if ( table [ 4 ] . children [ 0 ] . data ) { state [ 'status' ] = table [ 4 ] . children [ 0 ] . data . trim ( ) } else { state [ 'status' ] = table [ 4 ] . children [ 0 ] . children [ 0 ] . data . trim ( ) } } let details = $ ( '#details_0' ) . find ( 'tr' ) let day = "" let dayUnformated = "" let message = { } for ( let i = 0 ; i < details . length ; i ++ ) { let tr = details . get ( i ) if ( tr . children . length >= 8 ) { let idxsum = 0 if ( tr . children . length >= 9 ) { day = tr . children [ 0 ] . children [ 0 ] . data . trim ( ) dayUnformated = day . split ( ',' ) [ 1 ] . trim ( ) day = moment . tz ( dayUnformated , "DD MMMM YYYY" , 'pt' , zone ) . format ( ) message = { day : day , status : [ ] } messages . push ( message ) idxsum = 1 } let hours = tr . children [ 0 + idxsum ] . children [ 0 ] . data . trim ( ) let time = moment . tz ( dayUnformated + ' ' + hours , "DD MMMM YYYY HH:mm" , 'pt' , zone ) . format ( ) let add = { time : time , status : tr . children [ 2 + idxsum ] . children [ 0 ] . data . trim ( ) , local : tr . children [ 6 + idxsum ] . children [ 0 ] . data . trim ( ) } message . status . push ( add ) } } } catch ( error ) { return cb ( error ) } cb ( null , new CttInfo ( id , state , messages ) ) }
Create ctt entity from html
@param id
@param html
@param cb
Create ctt entity from html