Skip to content

Commit

Permalink
Add Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
emafazillah committed Mar 29, 2020
1 parent 7056f82 commit 75eeea7
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Covid-19 Updates Bot
Get Malaysian Covid-19 Updates. Data from 2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE, https://github.com/CSSEGISandData/COVID-19. Updates will be sent via Telegram.
Get Malaysia Covid-19 Updates. Data from 2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE, https://github.com/CSSEGISandData/COVID-19. Updates will be sent via Telegram.
60 changes: 33 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require('dotenv').config();
const core = require('@actions/core');
const github = require('@actions/github');
const { StringStream } = require('scramjet');
const request = require('request');
const Telegram = require('node-telegram-bot-api');
Expand All @@ -7,30 +9,34 @@ const bot = new Telegram(process.env.TELEGRAM_TOKEN);
const URL = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/';
const CSV = '.csv';

const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
let formattedYesterdayDate = '';
const getMonth = yesterday.getMonth() + 1;
if (getMonth < 10) {
formattedYesterdayDate = '0' + getMonth + '-' + yesterday.getDate() + '-' + yesterday.getFullYear();
} else {
formattedYesterdayDate = getMonth + '-' + yesterday.getDate() + '-' + yesterday.getFullYear();
}

const generateMessage = object =>
`Malaysia COVID-19 Updates as ${yesterday.toDateString()};
Confirmed: ${object.Confirmed}.
Deaths: ${object.Deaths}.
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);
});
try {
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
let formattedYesterdayDate = '';
const getMonth = yesterday.getMonth() + 1;
if (getMonth < 10) {
formattedYesterdayDate = '0' + getMonth + '-' + yesterday.getDate() + '-' + yesterday.getFullYear();
} else {
formattedYesterdayDate = getMonth + '-' + yesterday.getDate() + '-' + yesterday.getFullYear();
}

const generateMessage = object =>
`Malaysia COVID-19 Updates as ${yesterday.toDateString()};
Confirmed: ${object.Confirmed}.
Deaths: ${object.Deaths}.
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);
});
} catch (error) {
core.setFailed(error.message);
}
Loading

0 comments on commit 75eeea7

Please sign in to comment.