Skip to content

Commit 4904f69

Browse files
committed
removed all emojis, added country search by name, iso code
1 parent 8ba51dd commit 4904f69

File tree

8 files changed

+54
-1336
lines changed

8 files changed

+54
-1336
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
.DS_Store
2+
.DS_Store
3+
.now/

app.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require('express');
22
const app = express();
3+
const lookup = require('country-code-lookup');
34

45
const port = process.env.PORT || 3001;
56

@@ -22,6 +23,7 @@ app.get('/', (req, res) => {
2223

2324
app.get('/:country', (req, res) => {
2425
const { country } = req.params;
26+
let lookupObj = null;
2527
const format = req.query.format ? req.query.format : '';
2628

2729
if (!country || country === 'all') {
@@ -36,13 +38,32 @@ app.get('/:country', (req, res) => {
3638
}).catch(error => res.send(error));
3739
}
3840

41+
try {
42+
lookupObj = lookup.byIso(country)
43+
|| lookup.byFips(country)
44+
|| lookup.byCountry(country);
45+
} catch (error) {
46+
lookupObj = lookup.byFips(country) || lookup.byCountry(country);
47+
}
48+
if (!lookupObj) {
49+
return res.send(`
50+
Country not found.
51+
Try full country name or country code.
52+
Ex:
53+
- /UK: for United Kingdom
54+
- /US: for United States of America.
55+
- /India: for India.
56+
`);
57+
}
58+
const { iso2 } = lookupObj;
59+
3960
if (format.toLowerCase() === 'json') {
40-
return getJSONDataForCountry(country).then(result => {
61+
return getJSONDataForCountry(iso2).then(result => {
4162
return res.json(result);
4263
}).catch(error => res.send(error));
4364
}
44-
45-
return getCountryTable(country).then(result => {
65+
66+
return getCountryTable(iso2).then(result => {
4667
return res.send(result);
4768
}).catch(error => res.send(error));
4869
});

lib/byCountry.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ exports.getJSONData = async () => {
6666
return result.data;
6767
}
6868

69-
exports.getJSONDataForCountry = async (country) => {
69+
exports.getJSONDataForCountry = async (countryCode) => {
7070
const result = await axios('https://coronavirus-tracker-api.herokuapp.com/all');
7171
const { latest, confirmed, deaths, recovered } = result.data;
72-
const countryData = getDataByState(confirmed, deaths, recovered, country)
73-
.filter(obj => obj.country === country);
72+
const countryData = getDataByState(confirmed, deaths, recovered, countryCode)
73+
.filter(obj => obj.countryCode === countryCode);
7474
return countryData;
7575
}
7676

77-
exports.getCountryTable = async (country) => {
77+
exports.getCountryTable = async (countryCode) => {
7878
const head = [
7979
'',
8080
'State',
81-
'Confirmed',
82-
'Recovered 😃',
83-
'Deaths 😞',
84-
'Active 😷',
81+
'Confirmed',
82+
'Recovered',
83+
'Deaths',
84+
'Active',
8585
'Mortality %',
8686
'Recovered %',
87-
'1 Day 🔺',
88-
'1 Week 🔺',
87+
'1 Day ',
88+
'1 Week ',
8989
// 'RoG',
9090
// '🏳',
9191
];
@@ -98,11 +98,11 @@ exports.getCountryTable = async (country) => {
9898
});
9999
const result = await axios('https://coronavirus-tracker-api.herokuapp.com/all');
100100
const { latest, confirmed, deaths, recovered } = result.data;
101-
const countryData = getDataByState(confirmed, deaths, recovered, country)
102-
.filter(obj => obj.country === country);
101+
const countryData = getDataByState(confirmed, deaths, recovered, countryCode)
102+
.filter(obj => obj.countryCode === countryCode);
103103
const totalStats = getTotalStats(countryData);
104104
table.push({
105-
[country]: [
105+
[countryData[0].country]: [
106106
'Total',
107107
getConfirmed(totalStats.confirmed),
108108
getRecovered(totalStats.recovered),

lib/corona.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ exports.getCompleteTable = async () => {
8282
const head = [
8383
'',
8484
'Country',
85-
'Confirmed',
86-
'Recovered 😃',
87-
'Deaths 😞',
88-
'Active 😷',
85+
'Confirmed',
86+
'Recovered',
87+
'Deaths',
88+
'Active',
8989
'Mortality %',
9090
'Recovered %',
91-
'1 Day 🔺',
92-
'1 Week 🔺',
91+
'1 Day ',
92+
'1 Week ',
9393
// 'RoG',
9494
// '🏳',
9595
];
@@ -123,7 +123,7 @@ exports.getCompleteTable = async () => {
123123
countryData.forEach(cd => {
124124
const countryEmoji = getEmoji(cd.countryCode);
125125
const values = [
126-
getCountry(cd.country),
126+
getCountry(`${cd.country} (${cd.countryCode})`),
127127
getConfirmed(cd.confirmed),
128128
getRecovered(cd.recovered),
129129
getDeaths(cd.deaths),

lib/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ e.getOneDayChange = ({ confirmedByDay }) => {
104104
const present = confirmedByDay.length - 1;
105105
const dailyChange = confirmedByDay[present] - confirmedByDay[present - 1];
106106
return {
107-
content: `${h(dailyChange)}🔺`,
107+
content: `${h(dailyChange)}`,
108108
hAlign: 'right',
109109
};
110110
};
@@ -113,7 +113,7 @@ e.getOneWeekChange = ({ confirmedByDay }) => {
113113
const present = confirmedByDay.length - 1;
114114
const weeklyChange = confirmedByDay[present] - confirmedByDay[present - 7];
115115
return {
116-
content: `${h(weeklyChange)}🔺`,
116+
content: `${h(weeklyChange)}`,
117117
hAlign: 'right',
118118
};
119119
};

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"axios": "^0.19.2",
2222
"chalk": "^3.0.0",
2323
"cli-table3": "^0.5.1",
24+
"country-code-lookup": "0.0.16",
2425
"emoji-flags": "^1.2.0",
2526
"express": "^4.17.1",
2627
"humanize-number": "0.0.2",

0 commit comments

Comments
 (0)