Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: add option display country chart by days #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ const xcolor = cli.flags.xcolor;
const sortBy = cli.flags.sort;
const reverse = cli.flags.reverse;
const limit = Math.abs(cli.flags.limit);
const lastdays = Math.abs(cli.flags.lastdays);
const chart = cli.flags.chart;
const log = cli.flags.log;
const bar = cli.flags.bar;
const minimal = cli.flags.minimal;
const json = cli.flags.json;
const options = { sortBy, limit, reverse, minimal, chart, log, json, bar };
const options = { sortBy, limit, reverse, minimal, chart, log, lastdays, json, bar };

(async () => {
// Init.
Expand Down
8 changes: 7 additions & 1 deletion utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = meow(
${green(`corona`)} ${cyan(`china`)}
${green(`corona`)} ${cyan(`states`)}
${green(`corona`)} ${yellow(`--bar`)}
${green(`corona`)} ${cyan(`china`)} ${yellow(`--chart`)}
${green(`corona`)} ${cyan(`china`)} ${yellow(`--chart`)}
${green(`corona`)} ${cyan(`china`)} ${yellow(`--chart`)} ${yellow(`--lastdays 60`)}
${green(`corona`)} ${cyan(`china`)} ${yellow(`--chart`)} ${yellow(`--log`)}
${green(`corona`)} ${yellow(`--sort`)} ${cyan(`cases-today`)}
${green(`corona`)} ${yellow(`-s`)} ${cyan(`critical`)}
Expand Down Expand Up @@ -63,6 +64,11 @@ module.exports = meow(
default: false,
alias: 'c'
},
lastdays: {
type: 'number',
default: 30,
alias: 'd'
},
log: {
type: 'boolean',
default: false,
Expand Down
10 changes: 7 additions & 3 deletions utils/getCountryChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const moment = require('moment');
const blessed = require('blessed');
const contrib = require('blessed-contrib');

module.exports = async (spinner, countryName, { chart, log }) => {
module.exports = async (spinner, countryName, { chart, log, lastdays }) => {
if (countryName && chart) {
const [err, response] = await to(
axios.get(`https://corona.lmao.ninja/v2/historical/${countryName}`)
axios.get(`https://corona.lmao.ninja/v2/historical/${countryName}`, {
params: {
lastdays
}
})
);
handleError(`API is down, try again later.`, err, false);
if (response.status === 404) {
Expand Down Expand Up @@ -39,7 +43,7 @@ module.exports = async (spinner, countryName, { chart, log }) => {
showLegend: true,
legend: { width: 20 },
wholeNumbersOnly: false,
label: countryName.toUpperCase()
label: `${countryName.toUpperCase()} cases in the last ${lastdays} days`
});
const dates = Object.keys(response.data.timeline.cases).map(shortDate);
const cases = Object.values(response.data.timeline.cases);
Expand Down