Skip to content

Commit

Permalink
Merge pull request #2 from emafazillah/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
emafazillah authored Mar 31, 2020
2 parents fa82283 + 00597c1 commit 82a2e6d
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/send-message.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'GitHub Action for COVID-19 Updates'
name: 'GitHub Action for COVID-19 Update'

on:
push:
Expand All @@ -19,3 +19,6 @@ jobs:
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
URL: 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/'
CSV: '.csv'
COUNTRY: 'Malaysia'
201 changes: 199 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,199 @@
# Covid-19 Updates Bot
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.
# Covid-19 Update Bot
## Description
Get Covid-19 Update by country. Data from 2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE, https://github.com/CSSEGISandData/COVID-19. Update will be sent via Telegram.

## Example Usage
Update `send-message.yml` as below;
```YAML
...
- cron: '0 12 * * *'

...
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
...
COUNTRY: 'Malaysia'
```
## List of Countries
Country |
:---|
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Brazil
Brunei
Bulgaria
Burkina Faso
Burma
Cabo Verde
Cambodia
Cameroon
Canada
Central African Republic
Chad
Chile
China
Colombia
Congo (Brazzaville)
Congo (Kinshasa)
Costa Rica
Cote d'Ivoire
Croatia
Cuba
Cyprus
Czechia
Denmark
Diamond Princess
Djibouti
Dominica
Dominican Republic
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Fiji
Finland
France
Gabon
Gambia
Georgia
Germany
Ghana
Greece
Grenada
Guatemala
Guinea
Guinea-Bissau
Guyana
Haiti
Holy See
Honduras
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Israel
Italy
Jamaica
Japan
Jordan
Kazakhstan
Kenya
Korea, South
Kosovo
Kuwait
Kyrgyzstan
Laos
Latvia
Lebanon
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Madagascar
Malaysia
Maldives
Mali
Malta
Mauritania
Mauritius
Mexico
Moldova
Monaco
Mongolia
Montenegro
Morocco
Mozambique
MS Zaandam
Namibia
Nepal
Netherlands
New Zealand
Nicaragua
Niger
Nigeria
North Macedonia
Norway
Oman
Pakistan
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Poland
Portugal
Qatar
Romania
Russia
Rwanda
Saint Kitts and Nevis
Saint Lucia
Saint Vincent and the Grenadines
San Marino
Saudi Arabia
Senegal
Serbia
Seychelles
Singapore
Slovakia
Slovenia
Somalia
South Africa
Spain
Sri Lanka
Sudan
Suriname
Sweden
Switzerland
Syria
Taiwan*
Tanzania
Thailand
Timor-Leste
Togo
Trinidad and Tobago
Tunisia
Turkey
Uganda
Ukraine
United Arab Emirates
United Kingdom
Uruguay
US
Uzbekistan
Venezuela
Vietnam
West Bank and Gaza
Zambia
Zimbabwe
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +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.'
description: 'Get Covid-19 Update by country. 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.'
description: 'COVID-19 Update on confirmed, deaths, recovered and active.'
runs:
using: 'node12'
main: 'index.js'
52 changes: 36 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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');
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 URL = process.env.URL.toString();
const CSV = process.env.CSV.toString();
const COUNTRY = process.env.COUNTRY.toString();

try {
const today = new Date();
Expand All @@ -21,22 +21,42 @@ try {
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}.`;
const generateMessage = (country, totalConfirmed, totalDeaths, totalRecovered, totalActive) =>
`${country} COVID-19 Update as ${yesterday.toDateString()};
Total Confirmed: ${totalConfirmed}.
Total Deaths: ${totalDeaths}.
Total Recovered: ${totalRecovered}.
Total Active: ${totalActive}.`;

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;
}

// 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);
getResult(COUNTRY)
.then(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);
});

const message = generateMessage(COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive);
bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message);
});

} catch (error) {
core.setFailed(error.message);
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"homepage": "https://github.com/emafazillah/covid19-updates-bot#readme",
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/github": "^2.1.1",
"dotenv": "^8.2.0",
"node-telegram-bot-api": "^0.40.0",
"request": "^2.88.2",
Expand Down

0 comments on commit 82a2e6d

Please sign in to comment.