//@liv-in-sky 28.9.21 18:00
//tabellenerstellung: https://netgrade.de/html-tabellen-generator/#
// forum: https://forum.iobroker.net/topic/48093/tabelle-covid-kennzahlen-bayern
const cheerio = require('cheerio');
const request = require('request');
let myDP='0_userdata.0.CONTROL-OWN.AAATEST.COVID-BAYERN.Table'
let mySchedule1=" 18 */4 * * * "; // alle 4 stunden bei minute 12
schedule(mySchedule1, function () {
request('https://www.lgl.bayern.de/gesundheit/infektionsschutz/infektionskrankheiten_a_z/coronavirus/karte_coronavirus/index.htm#wKennzahlen',(error, response, html)=>{
if (response.statusCode==200){ //log(html)
const $ = cheerio.load(html)
const list5 = $('*')
.find('table.blockelement > tbody >tr > td ')
.toArray()
.map(element => { return $(element).text()});// log(list5.length +"---"+list5)
// log(list5[3])
let htmlTeil=`<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-0ord{background-color:#ffcb2f;color:#000000;text-align:center}
.tg .tg-s6z2{background-color:#EFDF8E;color:#000000;text-align:left}
</style>`
+"<table class='tg'>"
for(let i=0;i<30-1;i+=2){
let helper=list5[i].replace("1)","").replace("2)","").replace("4)","").replace("3)","").replace("100.000","100k").replace("7-Tage","7d").replace("Einwohner","EW")
log(helper+" ----- " +list5[i+1] )
htmlTeil=htmlTeil+`<tr><th class="tg-s6z2">${helper}</th><th class="tg-0ord">${list5[i+1] }</th></tr>`
}
htmlTeil=htmlTeil+"</table>"
log(htmlTeil)
setState(myDP,htmlTeil)
}});
});