-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
DEV: Added multiple countries view #104
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const axios = require('axios'); | ||
const numberFormat = require('./numberFormat'); | ||
const exitCountry = require('./exitCountry'); | ||
const to = require('await-to-js').default; | ||
const handleError = require('cli-handle-error'); | ||
|
||
module.exports = async (spinner, table, states, countryName, options) => { | ||
if (countryName && !states && !options.chart) { | ||
const [err, response] = await to( | ||
axios.get(`https://corona.lmao.ninja/v2/countries/${countryName}`) | ||
); | ||
exitCountry(err, spinner, countryName); | ||
err && spinner.stopAndPersist(); | ||
handleError(`API is down, try again later.`, err, false); | ||
const thisCountry = response.data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's about multiple countries, maybe the name should have "countries" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree having countries as variable name seems more meaningful. I have changed that in the latest commit. |
||
|
||
// Format. | ||
const format = numberFormat(options.json); | ||
|
||
thisCountry.map(data => table.push([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in line 10, since https://corona.lmao.ninja/v2/countries/${countryName} refers to a single country, has this .map() worked ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a condition here, since previously it worked only for multiple countries input. Now it will work for single country, but the functionality here is for multiple country as mentioned above (#104 (comment)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the output when I've tried to run this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have fixed this issue in the latest commit, thanks for mentioning. Kindly test and update. |
||
`—`, | ||
data.country, | ||
format(data.cases), | ||
format(data.todayCases), | ||
format(data.deaths), | ||
format(data.todayDeaths), | ||
format(data.recovered), | ||
format(data.active), | ||
format(data.critical), | ||
format(data.casesPerOneMillion) | ||
])); | ||
spinner.stopAndPersist(); | ||
console.log(table.toString()); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this getting just 1 country ? Example:
https://corona.lmao.ninja/v2/countries/Brazil gets data from Brazil only. Shouldn't it stop on "/countries" ?
Click the link to see it: https://corona.lmao.ninja/v2/countries/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue #54 description states that we need to provide multiple countries to the command line input, for example in this case to test (since not yet deployed) the command :
node index.js --s country algeria,france,italy
Hence we are using the api which allows to get the specified countries input params :
https://corona.lmao.ninja/v2/countries/:countryList
{where :countryList -> (algeria,france,italy) in this case}
Thanks