Skip to content

Commit 6de7019

Browse files
committed
added last updated
1 parent 584479f commit 6de7019

File tree

6 files changed

+62
-13
lines changed

6 files changed

+62
-13
lines changed

app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ app.get('/', (req, res) => {
2222

2323
if (format.toLowerCase() === 'json') {
2424
return getJSONData().then(result => {
25-
res.setHeader('Cache-Control', 's-maxage=86400');
25+
res.setHeader('Cache-Control', 's-maxage=900');
2626
return res.json(result);
2727
}).catch(error => errorHandler(error, res));
2828
}
@@ -34,7 +34,6 @@ app.get('/', (req, res) => {
3434
});
3535

3636
app.get('/:country', (req, res) => {
37-
3837
const { country } = countryUpperCase(req.params);
3938
let lookupObj = null;
4039
const format = req.query.format ? req.query.format : '';

lib/byCountry.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525

2626
function getDataByState(confirmed, deaths, recovered) {
2727
const countryMap = {};
28+
const lastUpdated = confirmed.last_updated;
2829
const confirmedMap = _.keyBy(confirmed.locations, (i) => i.country + i.province);
2930
const recoveredMap = _.keyBy(recovered.locations, (i) => i.country + i.province);
3031
const deathsMap = _.keyBy(deaths.locations, (i) => i.country + i.province);
@@ -43,6 +44,7 @@ function getDataByState(confirmed, deaths, recovered) {
4344
confirmedByDay: helpers.historyObjToArr(confirmedMap[mapKey].history),
4445
recoveredByDay: helpers.historyObjToArr(recoveredMap[mapKey].history),
4546
deathsByDay: helpers.historyObjToArr(recoveredMap[mapKey].history),
47+
lastUpdated,
4648
};
4749
}
4850
});
@@ -139,5 +141,6 @@ exports.getCountryTable = async (countryCode) => {
139141
table.push({ [rank++]: values })
140142
});
141143
}
142-
return table.toString() + footer;
144+
const lastUpdated = countryData[0].lastUpdated;
145+
return table.toString() + footer(lastUpdated);
143146
}

lib/corona.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525

2626
function getDataByCountry(confirmed, deaths, recovered) {
2727
const countryMap = {};
28+
const lastUpdated = confirmed.last_updated;
2829
const confirmedMap = _.keyBy(confirmed.locations, (i) => i.country + i.province);
2930
const recoveredMap = _.keyBy(recovered.locations, (i) => i.country + i.province);
3031
const deathsMap = _.keyBy(deaths.locations, (i) => i.country + i.province);
@@ -42,6 +43,7 @@ function getDataByCountry(confirmed, deaths, recovered) {
4243
confirmedByDay: helpers.historyObjToArr(confirmedMap[mapKey].history),
4344
recoveredByDay: helpers.historyObjToArr(recoveredMap[mapKey].history),
4445
deathsByDay: helpers.historyObjToArr(recoveredMap[mapKey].history),
46+
lastUpdated,
4547
};
4648
} else {
4749
countryMap[countryName].confirmed += confirmedMap[mapKey].latest;
@@ -136,5 +138,6 @@ exports.getCompleteTable = async () => {
136138
]
137139
table.push({ [rank++]: values })
138140
});
139-
return table.toString() + footer;
141+
const lastUpdated = countryData[0].lastUpdated;
142+
return table.toString() + footer(lastUpdated);
140143
}

lib/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ e.countryUpperCase = (countryParams) => {
153153
return countryParams;
154154
};
155155

156-
e.footer = `
156+
e.footer = (lastUpdated) => `
157157
158158
Stay safe. Stay inside.
159159
160160
Code: https://github.com/sagarkarira/coronavirus-tracker-cli/
161161
Twitter: http://twitter.com/ekrysis
162162
163+
Last Updated on: ${moment(lastUpdated).utc().format('DD-MMM-YYYY HH:MM')} UTC
164+
163165
`;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coronavirus-tracker-cli",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "track conronavirus cases from cli",
55
"main": "./lib/corona.js",
66
"bin": {

readme.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,50 @@ Track coronavirus from cli
66

77
<img src="https://i.ibb.co/cxJkRHf/screenshot.png" width="960" height="720">
88

9-
## Curl
9+
## CURL
1010

11-
All: `curl https://corona-stats.online/`
11+
### Complete Data
1212

13-
Country wise: `curl https://corona-stats.online/<country>`
13+
```
14+
curl https://corona-stats.online/
15+
```
1416

15-
Example:
17+
### Filter by Country Stats
1618

17-
US: `curl https://corona-stats.online/US`
19+
```
20+
curl https://corona-stats.online/<country>
21+
```
1822

19-
Italy: `curl https://corona-stats.online/Italy`
23+
where <country> can be country name or its ISO code.
24+
25+
- US: ```curl https://corona-stats.online/US```
26+
- Italy: ```curl https://corona-stats.online/Italy```
27+
- UK: ```curl https://corona-stats.online/UK``` or ```curl https://corona-stats.online/GB```
28+
29+
30+
## API
31+
32+
Add `?format=json` at the end of any API to get json formatted data.
33+
34+
**Example:**
35+
36+
```
37+
curl https://corona-stats.online?format=json
38+
```
39+
40+
## Local Command (For coloured ouput)
41+
42+
**Install**
43+
44+
```
45+
npm install corona-tracker-cli -g
46+
```
47+
48+
**Run command**
49+
50+
```
51+
corona
52+
```
2053

2154
### ToDos
2255

@@ -26,6 +59,15 @@ Italy: `curl https://corona-stats.online/Italy`
2659
* Add growth rate. (linear regression)
2760
* Add latest updates from reddit / twitter.
2861

62+
### Other Regional Trackers.
63+
64+
* [Italy](http://opendatadpc.maps.arcgis.com/apps/opsdashboard/index.html#/b0c68bce2cce478eaac82fe38d4138b1)
65+
* [India](https://www.covid19india.org/)
66+
* [USA](https://www.npr.org/sections/health-shots/2020/03/16/816707182/map-tracking-the-spread-of-the-coronavirus-in-the-u-s)
67+
* [France](https://veille-coronavirus.fr/)
68+
* [Japan](https://covid19japan.com/)
69+
70+
2971
### Thanks to
3072

3173
* [CSSEGISandData](https://github.com/CSSEGISandData/COVID-19) for the data.
@@ -40,4 +82,4 @@ Italy: `curl https://corona-stats.online/Italy`
4082

4183
## License
4284

43-
This project is licensed under the MIT License
85+
[WTFPL](http://www.wtfpl.net/)

0 commit comments

Comments
 (0)