Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Get country region from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
emafazillah committed Mar 31, 2020
1 parent 75eeea7 commit 75fffa1
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,45 @@ try {
Recovered: ${object.Recovered}.
Active: ${object.Active}.`;

// TODO: Get country region from configuration
request.get(URL + formattedYesterdayDate + CSV)
.pipe(new StringStream())
.CSVParse({ skipEmptyLines: true, header: true })
.filter(object => (object.Country_Region === 'Malaysia'))
.map(async(object) => {
const message = generateMessage(object);
bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message);
// request.get(URL + formattedYesterdayDate + CSV)
// .pipe(new StringStream())
// .CSVParse({ skipEmptyLines: true, header: true })
// .filter(object => (object.Country_Region === 'Malaysia'))
// .map(async(object) => {
// const message = generateMessage(object);
// bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message);
// });

async function getResult(country) {
let arr = [];
await request
.get(URL + formattedYesterdayDate + CSV)
.pipe(new StringStream())
.CSVParse({ skipEmptyLines: true, header: true })
.filter(data => (data.Country_Region === country))
.consume(data => arr.push(data));
return arr;
}

getResult('Australia')
.then(result => {
// console.log('result: ', result);
let totalConfirmed = 0;
let totalDeaths = 0;
let totalRecovered = 0;
let totalActive = 0;
result.forEach(element => {
totalConfirmed = totalConfirmed + parseInt(element.Confirmed);
totalDeaths = totalDeaths + parseInt(element.Deaths);
totalRecovered = totalRecovered + parseInt(element.Recovered);
totalActive = totalActive + parseInt(element.Active);
});
// console.log('totalConfirmed: ', totalConfirmed);
// console.log('totalDeaths: ', totalDeaths);
// console.log('totalRecovered: ', totalRecovered);
// console.log('totalActive: ', totalActive);
});

} catch (error) {
core.setFailed(error.message);
}

0 comments on commit 75fffa1

Please sign in to comment.