From 75fffa10c828effd0fe822d4d65cea35de2221cd Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 12:13:56 +0800 Subject: [PATCH 1/6] Get country region from configuration --- index.js | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index ddbbbc4..cca6848 100644 --- a/index.js +++ b/index.js @@ -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); } \ No newline at end of file From b8dee1c3a4075a1e4a2042a39a5fd2ad5538039e Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 12:24:39 +0800 Subject: [PATCH 2/6] Refactor --- index.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index cca6848..58e9bb5 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ 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 COUNTRY = 'Australia'; try { const today = new Date(); @@ -21,12 +22,12 @@ 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 Updates as ${yesterday.toDateString()}; + Total Confirmed: ${totalConfirmed}. + Total Deaths: ${totalDeaths}. + Total Recovered: ${totalRecovered}. + Total Active: ${totalActive}.`; // request.get(URL + formattedYesterdayDate + CSV) // .pipe(new StringStream()) @@ -48,23 +49,23 @@ try { return arr; } - getResult('Australia') + getResult(COUNTRY) .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); + + const message = generateMessage(COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); + console.log('message: ', message); + // bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message); }); } catch (error) { From 6810f71de4f853e7b71e51861ec322e0b4a8432d Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 12:28:03 +0800 Subject: [PATCH 3/6] Refactor --- index.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 58e9bb5..387e9eb 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,6 @@ 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 COUNTRY = 'Australia'; try { const today = new Date(); @@ -28,15 +27,6 @@ try { Total Deaths: ${totalDeaths}. Total Recovered: ${totalRecovered}. Total Active: ${totalActive}.`; - - // 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 = []; @@ -49,7 +39,7 @@ try { return arr; } - getResult(COUNTRY) + getResult(process.env.COUNTRY) .then(result => { let totalConfirmed = 0; let totalDeaths = 0; @@ -63,9 +53,9 @@ try { totalActive = totalActive + parseInt(element.Active); }); - const message = generateMessage(COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); + const message = generateMessage(process.env.COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); console.log('message: ', message); - // bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message); + // bot.sendMessage(process.env.COUNTRY, message); }); } catch (error) { From 924a1c1ed6031a5000f185405a080e13804cdf8d Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 12:45:12 +0800 Subject: [PATCH 4/6] Refactor --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 387e9eb..93d107c 100644 --- a/index.js +++ b/index.js @@ -6,8 +6,9 @@ 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(); @@ -22,7 +23,7 @@ try { } const generateMessage = (country, totalConfirmed, totalDeaths, totalRecovered, totalActive) => - `${country} COVID-19 Updates as ${yesterday.toDateString()}; + `${country} COVID-19 Update as ${yesterday.toDateString()}; Total Confirmed: ${totalConfirmed}. Total Deaths: ${totalDeaths}. Total Recovered: ${totalRecovered}. @@ -39,7 +40,7 @@ try { return arr; } - getResult(process.env.COUNTRY) + getResult(COUNTRY) .then(result => { let totalConfirmed = 0; let totalDeaths = 0; @@ -53,9 +54,9 @@ try { totalActive = totalActive + parseInt(element.Active); }); - const message = generateMessage(process.env.COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); - console.log('message: ', message); - // bot.sendMessage(process.env.COUNTRY, message); + const message = generateMessage(COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); + // console.log('message: ', message); + bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message); }); } catch (error) { From 5be27049e51080ff3acb42ae3cf1361f9fbfabeb Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 13:11:03 +0800 Subject: [PATCH 5/6] Update README and configuration --- .github/workflows/send-message.yml | 5 +- README.md | 212 ++++++++++++++++++++++++++++- index.js | 2 - package.json | 1 - 4 files changed, 214 insertions(+), 6 deletions(-) diff --git a/.github/workflows/send-message.yml b/.github/workflows/send-message.yml index d2f49a1..9375484 100644 --- a/.github/workflows/send-message.yml +++ b/.github/workflows/send-message.yml @@ -1,4 +1,4 @@ -name: 'GitHub Action for COVID-19 Updates' +name: 'GitHub Action for COVID-19 Update' on: push: @@ -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' diff --git a/README.md b/README.md index 1cbd0f2..e85c064 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,210 @@ -# 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 +```YAML +on: + push: + schedule: + - cron: '0 12 * * *' + +jobs: + bot: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: 'Install node' + uses: actions/setup-node@v1 + - name: 'Install NPM dependencies' + run: npm install + - name: 'Run code' + run: node index.js + 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' +``` +## Country +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 \ No newline at end of file diff --git a/index.js b/index.js index 93d107c..ed10746 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ 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'); @@ -55,7 +54,6 @@ try { }); const message = generateMessage(COUNTRY, totalConfirmed, totalDeaths, totalRecovered, totalActive); - // console.log('message: ', message); bot.sendMessage(process.env.TELEGRAM_CHAT_ID, message); }); diff --git a/package.json b/package.json index 7e6778d..ea0a6c9 100644 --- a/package.json +++ b/package.json @@ -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", From 00597c1e439dcd53b79e2c843e5aee73e13a7e08 Mon Sep 17 00:00:00 2001 From: emafazillah Date: Tue, 31 Mar 2020 13:20:18 +0800 Subject: [PATCH 6/6] Update README --- README.md | 23 ++++++----------------- action.yml | 4 ++-- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e85c064..58e16a7 100644 --- a/README.md +++ b/README.md @@ -3,31 +3,20 @@ 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 -on: - push: - schedule: +... - cron: '0 12 * * *' -jobs: - bot: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: 'Install node' - uses: actions/setup-node@v1 - - name: 'Install NPM dependencies' - run: npm install - - name: 'Run code' - run: node index.js +... 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' ``` -## Country + +## List of Countries Country | :---| Afghanistan diff --git a/action.yml b/action.yml index ad879bd..b887851 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ 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' @@ -7,7 +7,7 @@ inputs: 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' \ No newline at end of file