Skip to content

Commit

Permalink
Fixed Global Increased Number data from worldometer
Browse files Browse the repository at this point in the history
  • Loading branch information
denven committed Mar 18, 2020
1 parent 5159cf8 commit d5105a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# dependencies
/node_modules
/scripts
/scripts/node_modules
/.pnp
.pnp.js

Expand Down
9 changes: 8 additions & 1 deletion scripts/updateGlobalCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ async function updateGlobalCases () {
let name = $(tableRows[index]).text().match(/[a-zA-Z ]+/g); // match country or place name

if(Array.isArray(name)){
let increasedNum = ( name[0].trim() !== 'Total' ?
$(tableRows[index+2]).text().trim().slice(1) :
$(tableRows[index+2]).text().trim()) || '0';
let country = {
name: name[0].trim(),
total: $(tableRows[index+1]).text().trim(),
increased: $(tableRows[index+2]).text().trim().slice(1) || '0',
increased: increasedNum,
dead: $(tableRows[index+3]).text().trim() || '0',
newDeath: $(tableRows[index+4]).text().trim().slice(1) || '0',
recovered: $(tableRows[index+5]).text().trim() || '0',
Expand All @@ -32,6 +35,9 @@ async function updateGlobalCases () {
perMppl: $(tableRows[index+8]).text().trim() || '0'
};
countries.push(country);

if( name[0].trim() === 'Total') break;

index += 9;

} else {
Expand All @@ -40,6 +46,7 @@ async function updateGlobalCases () {
};

let overall = countries.pop();
// console.log(overall);
if(countries.length > 0) {
let jsonData = {
time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
Expand Down

0 comments on commit d5105a6

Please sign in to comment.