Skip to content

Commit dce7c02

Browse files
author
Waren Gonzaga
committed
Add random health saying
1 parent 9c5fd1e commit dce7c02

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ app.get(['/plain','/cmd','/basic'], async (req, res, next) => {
4545
return next();
4646
});
4747

48+
// help options
49+
app.get(['/help','/manual'], async (req, res, next) => {
50+
const userAgent = req.headers['user-agent'];
51+
if (util.isCommandline(userAgent)) {
52+
await res.send(covid19.help());
53+
return null;
54+
}
55+
return next();
56+
});
57+
4858
// by country route for covid19 tracker
4959
app.get('/:country', async (req, res, next) => {
5060
const userAgent = req.headers['user-agent'],

lib/cli/index.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const
2121
cyanBright = (txt) => {return color.cyanBright.open+txt+color.cyanBright.close;},
2222
magentaBright = (txt) => {return color.magentaBright.open+txt+color.magentaBright.close;},
2323
redBright = (txt) => {return color.redBright.open+txt+color.redBright.close;},
24+
greenBright = (txt) => {return color.greenBright.open+txt+color.greenBright.close;},
2425
// background ansi color
2526
cyanBG = (txt) => {return color.bgCyan.open+txt+color.bgCyan.close;},
2627
// horizontal line
@@ -29,6 +30,13 @@ const
2930

3031
// package.json information
3132
const pkg = JSON.parse(fs.readFileSync('package.json'));
33+
const say = JSON.parse(fs.readFileSync('./lib/sayings/threads.json'));
34+
35+
// random sayings
36+
const randomSay = () => {
37+
let random = Math.floor(Math.random() * say.length);
38+
return say[random];
39+
};
3240

3341
// format data
3442
const formatNumber = (value) => {
@@ -68,6 +76,27 @@ const source = 'Source: https://www.worldometers.info/coronavirus/',
6876
sourceCountry = {colSpan:5,content:source},
6977
repoCountry = {colSpan:5,content:repo};
7078

79+
// help menu
80+
exports.help = () => {
81+
const manual = `
82+
${line}
83+
COVID-19 Tracker CLI v${pkg.version} by Waren Gonzaga
84+
${line}
85+
86+
/country or /code ......... by country query
87+
ex. /philippines or /ph
88+
89+
/cmd ...................... if using CMD
90+
91+
/plain or /basic .......... if your cli does not support ansi encoding
92+
93+
${line}
94+
95+
"${randomSay()}"
96+
`;
97+
return manual+plainfooter;
98+
};
99+
71100
// covid19 global tracker
72101
exports.covid19globaltracker = (c, d, r, u) => {
73102
const cases = c, deaths = d, recovered = r, asof = new Date(u),
@@ -82,15 +111,15 @@ exports.covid19globaltracker = (c, d, r, u) => {
82111
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered), mortalityPercentage.toFixed(2), recoveredPercentage.toFixed(2)],
83112
[sourceGlobal],[repoGlobal]
84113
);
85-
return table.toString()+'\n'+footer;
114+
return table.toString()+'\n\n'+' '+'"'+green(randomSay())+'"'+footer;
86115
};
87116

88117
// covid19 country tracker
89118
exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
90119
const name = n, cases = c, todayCases = tC,
91120
deaths = d, todayDeaths = tD, recovered = r,
92121
active = a, critical = cl, casesPerOneMillion = cPOM,
93-
mortalityPercentage = (d/c)*100, recoveredPercentage = (r/c)*100,
122+
mortalityPercentage = (d/c)*100, recoveryPercentage = (r/c)*100,
94123
asof = new Date(u);
95124
table = new table3({
96125
head: [{colSpan:5,content:white('COVID-19 Tracker CLI v'+pkg.version+' - '+name+' Update')}],
@@ -100,11 +129,11 @@ exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
100129
[{colSpan:5,content:yellow('As of '+asof.toLocaleString()+' [Date:'+currentdate+']')}],
101130
[magenta('Cases'), red('Deaths'), green('Recovered'), cyan('Active'), cyanBright('Cases/Million')],
102131
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered), formatNumber(active), formatNumber(casesPerOneMillion)],
103-
[magentaBright('Today Cases'), redBright('Today Deaths'), redBright('Critical'), red('Mortality %'), green('Recovered %')],
104-
[formatNumber(todayCases), formatNumber(todayDeaths), formatNumber(critical), mortalityPercentage.toFixed(2), recoveredPercentage.toFixed(2)],
132+
[magentaBright('Today Cases'), redBright('Today Deaths'), redBright('Critical'), red('Mortality %'), greenBright('Recovery %')],
133+
[formatNumber(todayCases), formatNumber(todayDeaths), formatNumber(critical), mortalityPercentage.toFixed(2), recoveryPercentage.toFixed(2)],
105134
[sourceCountry],[repoCountry]
106135
);
107-
return table.toString()+'\n'+footer;
136+
return table.toString()+'\n\n'+' '+'"'+green(randomSay())+'"'+footer;
108137
};
109138

110139
exports.plainglobaltracker = (c, d, r, u) => {
@@ -127,6 +156,8 @@ exports.plainglobaltracker = (c, d, r, u) => {
127156
${line}
128157
${repo}
129158
${line}
159+
160+
"${randomSay()}"
130161
`;
131162
return visual+plainfooter;
132163
};
@@ -159,13 +190,14 @@ exports.plaincountrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
159190
${line}
160191
${repo}
161192
${line}
193+
194+
"${randomSay()}"
162195
`;
163196
return visual+plainfooter;
164197
};
165198

166199
// cli footer
167200
const footer = `
168-
Always wash your hands, stay safe...
169201
170202
---
171203
Love this project? Please consider buying me a cup of coffee!
@@ -177,8 +209,6 @@ const footer = `
177209

178210
// cli plain footer
179211
const plainfooter = `
180-
Always wash your hands, stay safe...
181-
182212
---
183213
Love this project? Please consider buying me a cup of coffee!
184214
[ warengonzaga.com/buymeacoffee ]

lib/sayings/threads.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
"Alays wash your hands, stay safe!",
3+
"Stay healthy, stay at home...",
4+
"Play online games with your friends",
5+
"Stay on your home!",
6+
"Avoid fake news...",
7+
"Eat healthy foods, sleep on time",
8+
"We will survive!",
9+
"Code with Love by Waren",
10+
"COVID-19 is a serious matter",
11+
"Don't touch your face! wash your hands",
12+
"Social distancing is real...",
13+
"Developer from Philippines",
14+
"Support open-source!",
15+
"A cup of coffee will keep this project updated",
16+
"Can you send some coffee to the developer?",
17+
"Stay at home, play games instead...",
18+
"Uninstall 2020, virus detected!",
19+
"Always wear a mask when you go outside",
20+
"Watch news to keep updated!",
21+
"Support the developer, buy him a coffee!"
22+
]

0 commit comments

Comments
 (0)