Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![License](https://img.shields.io/github/license/warengonzaga/covid19-tracker-cli.svg?style=for-the-badge)](https://github.com/warengonzaga/covid19-tracker-cli)
[![Powered By](https://img.shields.io/badge/Powered%20By-NodeJS-green.svg?style=for-the-badge)](https://nodejs.org)

![Github Banner](./lib/img/covid19-tracker-cli-github-banner.jpg)

**COVID-19 Tracker CLI** is an open-source NodeJS application for command line interface to track COVID-19 cases around the world. An optimized NodeJS application and a simple tracker with real-time updates from reliable data source. [Visit Wiki](https://github.com/warengonzaga/covid19-tracker-cli/wiki)

## Featured By
Expand Down Expand Up @@ -85,14 +87,13 @@ If you're facing a problem in using COVID-19 Tracker CLI please let me know by c

## To Do

* Improve CLI
* CI (CircleCI)
* Local Version
* Add Static Version
* Official Logo
* Sample Usage (gif)
* Add HTTP Headers (currently F)
* Code Refactor (I don't know what I'm doing)
* More Code Refactor! (I guess I know what I'm doing now... for sure)
* More... (have suggestions? let me know!)

## Community
Expand Down
12 changes: 6 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// node modules
const express = require('express'),
app = express(),
util = require('./bin/util'),
fs = require('fs'),
axios = require('axios'),
covid19 = require('./lib/cli');
const express = require('express'),
app = express(),
util = require('./bin/util'),
fs = require('fs'),
axios = require('axios'),
covid19 = require('./lib/cli');

// set port
const port = process.env.port || 7070;
Expand Down
129 changes: 65 additions & 64 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
/* eslint-disable no-await-in-loop */

const style = require('ansi-styles'),
fs = require('fs'),
table3 = require('cli-table3');
const style = require('ansi-styles'),
fs = require('fs'),
table3 = require('cli-table3');

// ansi style and colors

const
// table color
tblclr = (border) => {return cyan(border);},
// normal ansi colors
white = (txt) => {return style.white.open+txt+style.white.close;},
black = (txt) => {return style.black.open+txt+style.black.close;},
green = (txt) => {return style.green.open+txt+style.green.close;},
cyan = (txt) => {return style.cyan.open+txt+style.cyan.close;},
magenta = (txt) => {return style.magenta.open+txt+style.magenta.close;},
yellow = (txt) => {return style.yellow.open+txt+style.yellow.close;},
red = (txt) => {return style.red.open+txt+style.red.close;},
// bright ansi colors
cyanBright = (txt) => {return style.cyanBright.open+txt+style.cyanBright.close;},
magentaBright = (txt) => {return style.magentaBright.open+txt+style.magentaBright.close;},
redBright = (txt) => {return style.redBright.open+txt+style.redBright.close;},
// background ansi color
cyanBG = (txt) => {return style.bgCyan.open+txt+style.bgCyan.close;};

const axios = require('axios');

const tblopn = style.cyan.open,
tblcls = style.cyan.close;

const apiBaseURL = "https://corona.lmao.ninja";

// package.json information
const pkg = JSON.parse(fs.readFileSync('package.json'));
const pkg = JSON.parse(fs.readFileSync('package.json'));

// format data
const formatNumber = (num) => {
Expand All @@ -27,89 +41,76 @@ let ts = Date.now(),
year = date_ob.getFullYear(),
currentdate = month + "/" + date + "/" + year;

// table configuration
const borders = { 'top': tblclr('═'),
'top-mid': tblclr('╤'),
'top-left': tblclr('╔'),
'top-right': tblclr('╗'),
'bottom': tblclr('═'),
'bottom-mid': tblclr('╧'),
'bottom-left': tblclr('╚'),
'bottom-right': tblclr('╝'),
'left': tblclr('║'),
'left-mid': tblclr('╟'),
'mid': tblclr('─'),
'mid-mid': tblclr('┼'),
'right': tblclr('║'),
'right-mid': tblclr('╢'),
'middle': tblclr('│')};

// additional informaton
const source = 'Source: https://www.worldometers.info/coronavirus/',
repo = 'Code: https://github.com/warengonzaga/covid19-tracker-cli',
sourceGlobal = {colSpan:3,content:source},
repoGlobal = {colSpan:3,content:repo},
sourceCountry = {colSpan:4,content:source},
repoCountry = {colSpan:4,content:repo};

// covid19 global tracker
exports.covid19globaltracker = (c, d, r, u) => {
const cases = c, deaths = d, recovered = r, asof = new Date(u),
table = new table3({
head: [{colSpan:3,content:`${style.white.open}COVID-19 Tracker CLI v`+pkg.version+` - Global Update${style.white.close}`}],
chars: { 'top': `${tblopn}═${tblcls}`,
'top-mid': `${tblopn}╤${tblcls}`,
'top-left': `${tblopn}╔${tblcls}`,
'top-right': `${tblopn}╗${tblcls}`,
'bottom': `${tblopn}═${tblcls}`,
'bottom-mid': `${tblopn}╧${tblcls}`,
'bottom-left': `${tblopn}╚${tblcls}`,
'bottom-right': `${tblopn}╝${tblcls}`,
'left': `${tblopn}║${tblcls}` ,
'left-mid': `${tblopn}╟${tblcls}` ,
'mid': `${tblopn}─${tblcls}` ,
'mid-mid': `${tblopn}┼${tblcls}`,
'right': `${tblopn}║${tblcls}` ,
'right-mid': `${tblopn}╢${tblcls}` ,
'middle': `${tblopn}│${tblcls}` }
head: [{colSpan:3,content:white('COVID-19 Tracker CLI v'+pkg.version+' - Global Update')}],
chars: borders
});

table.push(
[{colSpan:3,content:style.gray.open+'As of '+asof.toLocaleString()+' [Date:'+currentdate+']'+style.gray.close}],
[`${style.magenta.open}Cases${style.magenta.close}`, `${style.red.open}Deaths${style.red.close}`, `${style.green.open}Recovered${style.green.close}`],
[{colSpan:3,content:yellow('As of '+asof.toLocaleString()+' [Date:'+currentdate+']')}],
[magenta('Cases'), red('Deaths'), green('Recovered')],
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered)],
[{colSpan:3,content:style.gray.open+`Source: https://www.worldometers.info/coronavirus/`+style.gray.close}],
[{colSpan:3,content:style.gray.open+`Code: https://github.com/warengonzaga/covid19-tracker-cli`+style.gray.close}]
[sourceGlobal],[repoGlobal]
);
return table.toString()+'\n'+footer;
};

const lastupdate = async () => {
return await axios.get(`${apiBaseURL}/all`).then(function(res){
const update = res.data.updated;
return update.toLocaleString();
});
};

// covid19 country tracker
exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
const name = n, cases = c, todayCases = tC,
deaths = d, todayDeaths = tD, recovered = r,
active = a, critical = cl, casesPerOneMillion = cPOM,
asof = new Date(u);
table = new table3({
head: [{colSpan:4,content:`${style.white.open}COVID-19 Tracker CLI v`+pkg.version+` - ${name} Update${style.white.close}`}],
chars: { 'top': `${tblopn}═${tblcls}`,
'top-mid': `${tblopn}╤${tblcls}`,
'top-left': `${tblopn}╔${tblcls}`,
'top-right': `${tblopn}╗${tblcls}`,
'bottom': `${tblopn}═${tblcls}`,
'bottom-mid': `${tblopn}╧${tblcls}`,
'bottom-left': `${tblopn}╚${tblcls}`,
'bottom-right': `${tblopn}╝${tblcls}`,
'left': `${tblopn}║${tblcls}` ,
'left-mid': `${tblopn}╟${tblcls}` ,
'mid': `${tblopn}─${tblcls}` ,
'mid-mid': `${tblopn}┼${tblcls}`,
'right': `${tblopn}║${tblcls}` ,
'right-mid': `${tblopn}╢${tblcls}` ,
'middle': `${tblopn}│${tblcls}` }
head: [{colSpan:4,content:white('COVID-19 Tracker CLI v'+pkg.version+' - '+name+' Update')}],
chars: borders
});

table.push(
[{colSpan:4,content:style.gray.open+'As of '+asof.toLocaleString()+' [Date:'+currentdate+']'+style.gray.close}],
[`${style.magenta.open}Cases${style.magenta.close}`, `${style.red.open}Deaths${style.red.close}`, `${style.green.open}Recovered${style.green.close}`,`${style.cyan.open}Active${style.cyan.close}`],
[{colSpan:4,content:yellow('As of '+asof.toLocaleString()+' [Date:'+currentdate+']')}],
[magenta('Cases'), red('Deaths'), green('Recovered'), cyan('Active')],
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered), formatNumber(active)],
[`${style.magentaBright.open}Today Cases${style.magentaBright.close}`, `${style.redBright.open}Today Deaths${style.red.close}`, `${style.redBright.open}Critical${style.redBright.close}`,`${style.cyanBright.open}Cases Per Million${style.cyanBright.close}`],
[magentaBright('Today Cases'), redBright('Today Deaths'), redBright('Critical'), cyanBright('Cases Per Million')],
[formatNumber(todayCases), formatNumber(todayDeaths), formatNumber(critical), formatNumber(casesPerOneMillion)],
[{colSpan:4,content:style.gray.open+`Source: https://www.worldometers.info/coronavirus/`+style.gray.close}],
[{colSpan:4,content:style.gray.open+`Code: https://github.com/warengonzaga/covid19-tracker-cli`+style.gray.close}]
[sourceCountry],[repoCountry]
);

return table.toString()+'\n'+footer;
};

// cli footer
const footer = `
Always wash your hands, stay safe...
Always wash your hands, stay safe...

---
Love this project? Please consider buying me a cup of coffee!
${style.yellow.open}warengonzaga.com/buymeacoffee${style.yellow.close}
${yellow('warengonzaga.com/buymeacoffee')}

---
Follow ${style.bgCyan.open}${style.black.open}@warengonzaga${style.black.close}${style.bgCyan.close} for more updates!
Follow ${cyanBG(black('@warengonzaga'))} for more updates!
\n`;
Binary file added lib/img/covid19-tracker-cli-github-banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "covid19-tracker-cli",
"version": "2.0.0",
"version": "2.1.0",
"description": "Track COVID-19 cases from command line interface",
"main": "app.js",
"scripts": {
Expand Down