Skip to content

Commit c8f2f6a

Browse files
committed
📦 NEW: Time update
1 parent 9ee0031 commit c8f2f6a

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ const sortBy = cli.flags.sort;
4747

4848
// Display data.
4949
spinner.start();
50-
await getWorldwide(table, states);
50+
const lastUpdated = await getWorldwide(table, states);
5151
await getCountry(spinner, table, states, country);
5252
await getStates(spinner, table, states, { sort: sortBy });
5353
await getAll(spinner, table, states, country, { sort: sortBy });
5454

55-
getUpdated();
56-
theEnd(states);
55+
theEnd(lastUpdated, states);
5756
})();

utils/getCountry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const chalk = require("chalk");
22
const axios = require("axios");
3-
const logSymbols = require("log-symbols");
3+
const sym = require("log-symbols");
44
const comma = require("comma-number");
55
const red = chalk.red;
66
const to = require("await-to-js").default;
@@ -17,7 +17,7 @@ module.exports = async (spinner, table, states, country) => {
1717
spinner.stopAndPersist();
1818
console.log(
1919
`${red(
20-
`${logSymbols.error} Nops. A country named "${country}" does not exist…`
20+
`${sym.error} Nops. A country named "${country}" does not exist…`
2121
)}\n`
2222
);
2323
process.exit(0);

utils/getWorldwide.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const to = require("await-to-js").default;
44
const handleError = require("cli-handle-error");
55

66
module.exports = async (table, states) => {
7-
if (!states) {
8-
const [err, all] = await to(axios.get(`https://corona.lmao.ninja/all`));
9-
handleError(`API is down, try again later.`, err, false);
7+
const [err, all] = await to(axios.get(`https://corona.lmao.ninja/all`));
8+
handleError(`API is down, try again later.`, err, false);
9+
let data = Object.values(all.data);
10+
data = data.map(d => comma(d));
1011

11-
let data = Object.values(all.data);
12-
data = data.map(d => comma(d));
12+
if (!states) {
1313
table.push([
1414
`—`,
1515
`Worldwide`,
@@ -23,4 +23,7 @@ module.exports = async (table, states) => {
2323
`—`
2424
]);
2525
}
26+
27+
const lastUpdated = Date(data[3]);
28+
return lastUpdated;
2629
};

utils/theEnd.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
const logSymbols = require("log-symbols");
1+
const sym = require("log-symbols");
22
const chalk = require("chalk");
33
const cyan = chalk.cyan;
44
const dim = chalk.dim;
55

66
const infoStates = () =>
7-
console.log(`
8-
\n${logSymbols.info} ${cyan(`KEY:`)}
7+
console.log(
8+
dim(`
9+
\n${sym.info} ${cyan(`KEY:`)}
910
${dim(`❯ `)}${cyan(`State:`)} Name of the state
1011
${dim(`❯ `)}${cyan(`Cases:`)} Total number of cases in a country
1112
${dim(`❯ `)}${cyan(`Cases (today):`)} Cases in 24 hours GMT/UTC
1213
${dim(`❯ `)}${cyan(`Deaths:`)} Total number of deaths in a state
1314
${dim(`❯ `)}${cyan(`Deaths (today):`)} Deaths in 24 hours GMT/UTC
1415
${dim(`❯ `)}${cyan(`Recovered:`)} Total number of recovered people
1516
${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients
16-
`);
17+
`)
18+
);
1719

1820
const infoCountries = () =>
19-
console.log(`
20-
\n${logSymbols.info} ${cyan(`KEY:`)}
21+
console.log(
22+
dim(`
23+
\n${sym.info} ${cyan(`KEY:`)}
2124
${dim(`❯ `)}${cyan(`Country:`)} Name of the country
2225
${dim(`❯ `)}${cyan(`Cases:`)} Total number of cases in a country
2326
${dim(`❯ `)}${cyan(`Cases (today):`)} Cases in 24 hours GMT/UTC
@@ -27,15 +30,17 @@ ${dim(`❯ `)}${cyan(`Recovered:`)} Total number of recovered people
2730
${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients
2831
${dim(`❯ `)}${cyan(`Critical:`)} Total number of critical patients
2932
${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million
30-
`);
33+
`)
34+
);
3135

32-
module.exports = async states => {
36+
module.exports = async (lastUpdated, states) => {
37+
console.log(dim(`${sym.info} ${cyan(`Last Updated:`)} ${lastUpdated}`));
3338
states && infoStates();
3439
!states && infoCountries();
3540
console.log(
36-
`\n${logSymbols.success} ${dim(
41+
`\n${sym.success} ${dim(
3742
`Star the repo for updates → https://git.io/corona-cli`
38-
)}\n${logSymbols.info} ${dim(
43+
)}\n${sym.info} ${dim(
3944
`Follow for more CLIs → https://twitter.com/MrAhmadAwais\n\n`
4045
)}`
4146
);

0 commit comments

Comments
 (0)