Skip to content

Commit

Permalink
Merge pull request #1 from emafazillah/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
emafazillah authored Mar 29, 2020
2 parents a4bda6a + 75eeea7 commit fa82283
Show file tree
Hide file tree
Showing 6 changed files with 422 additions and 28 deletions.
File renamed without changes.
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.
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'GitHub Action for COVID-19 Updates'
description: 'Get Malaysian Covid-19 Updates. Data from 2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE.'
inputs:
who-to-greet: # id of input
description: 'Yesterday date'
required: true
default: 'Yesterday date'
outputs:
time: # id of output
description: 'COVID-19 Updates on confirmed, deaths, recovered and active.'
runs:
using: 'node12'
main: 'index.js'
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 fa82283

Please sign in to comment.