mirror of
https://github.com/danbulant/covid
synced 2026-06-23 08:42:10 +00:00
Parse global data
This commit is contained in:
parent
4adbb66787
commit
489c9a8c4b
1 changed files with 29 additions and 8 deletions
|
|
@ -1,21 +1,42 @@
|
|||
const got = require("got");
|
||||
const cheerio = require("cheerio");
|
||||
|
||||
module.exports = async()=>{
|
||||
var res = got("https://www.worldometers.info/coronavirus/");
|
||||
function execShellCommand(cmd) {
|
||||
const exec = require('child_process').exec;
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
resolve(stdout ? stdout : stderr);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async () => {
|
||||
console.log("Fetching...");
|
||||
var res = await execShellCommand("curl https://www.worldometers.info/coronavirus/");
|
||||
|
||||
console.log("Parsing");
|
||||
const $ = cheerio.load(res);
|
||||
var table = $("tbody");
|
||||
var cases = $(".maincounter-number");
|
||||
|
||||
var all = cases[0].text();
|
||||
var death = cases[1].text();
|
||||
var recovered = cases[2].text();
|
||||
var all = cases[0].childNodes[1].children[0].data;
|
||||
var death = cases[1].childNodes[1].children[0].data;
|
||||
var recovered = cases[2].childNodes[1].children[0].data;
|
||||
|
||||
console.log("[ALL] " + all);
|
||||
console.log("[DEATH] " + death);
|
||||
console.log("[RECOVERED] " + recovered);
|
||||
|
||||
console.log("Done");
|
||||
}
|
||||
|
||||
if(require.main == module){
|
||||
module.exports();
|
||||
}
|
||||
(async () => {
|
||||
if (require.main == module) {
|
||||
var keepingAlive = setInterval(() => {}, 1000);
|
||||
await module.exports();
|
||||
clearInterval(keepingAlive);
|
||||
}
|
||||
})();
|
||||
Loading…
Reference in a new issue