Skip to content

Commit c85129b

Browse files
author
ExpDev07
committed
/all
1 parent 8243d7c commit c85129b

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,43 @@
22

33
> This is a fast (< 200ms) and basic API for tracking development of the new coronavirus (2019-nCoV). It's written in python using 🍼 Flask.
44
5-
## Live version
6-
View the live version here: [https://coronavirus-tracker-api.herokuapp.com/latest](https://coronavirus-tracker-api.herokuapp.com/latest).
5+
## Endpoints
6+
7+
All requests must be made to the base url: ``https://coronavirus-tracker-api.herokuapp.com``. You can try them out in your browser to further inspect responses.
8+
9+
Getting confirmed cases, deaths, and recoveries:
10+
```http
11+
GET /all
12+
```
13+
```json
14+
{ latest: { ... }, confirmed: { ... }, deaths: { ... }, recovered: { ... } }
15+
```
16+
17+
Getting just confirmed:
18+
```http
19+
GET /confirmed
20+
```
21+
```json
22+
{ latest: 42767, locations: [ ... ] }
23+
```
24+
25+
Getting just deaths:
26+
```http
27+
GET /deaths
28+
```
29+
30+
Getting just recoveries:
31+
```http
32+
GET /recovered
33+
```
34+
735

836
## Data
37+
938
The data is retrieved programatically and re-formatted from the [2019 Novel Coronavirus (nCoV) Data Repository, provided by JHU CCSE](https://github.com/CSSEGISandData/2019-nCoV).
1039

1140
## License
41+
1242
The data is available to the public strictly for educational and academic research purposes.
1343

1444
## Prerequisites

app/data/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
base_url = 'https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/time_series/time_series_2019-ncov-%s.csv';
1010

1111
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
12-
def get_data(type):
12+
def get_data(category):
1313
"""
1414
Retrieves the data for the provided type.
1515
"""
1616

17-
# Adhere to type naming standard.
18-
type = type.lower().capitalize();
17+
# Adhere to category naming standard.
18+
category = category.lower().capitalize();
1919

2020
# Request the data
21-
request = requests.get(base_url % type)
21+
request = requests.get(base_url % category)
2222
text = request.text
2323

2424
# Parse the CSV.
@@ -51,8 +51,14 @@ def get_data(type):
5151
'latest': int(list(history.values())[-1]),
5252
})
5353

54+
# Latest total.
55+
latest = sum(map(lambda location: location['latest'], locations))
56+
5457
# Return the final data.
55-
return locations
58+
return {
59+
'locations': locations,
60+
'latest': latest
61+
}
5662

5763

5864

app/routes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from . import confirmed
22
from . import deaths
33
from . import recovered
4-
from . import latest
4+
from . import all

app/routes/all.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
from app import app
33
from app.data import get_data
44

5-
@app.route('/deaths')
6-
def deaths():
7-
return jsonify(get_data('deaths'))
5+
@app.route('/all')
6+
def all():
7+
# Get all the categories.
8+
confirmed = get_data('confirmed')
9+
deaths = get_data('deaths')
10+
recovered = get_data('recovered')
11+
12+
return jsonify({
13+
# Data.
14+
'confirmed': confirmed,
15+
'deaths': deaths,
16+
'recovered': recovered,
17+
18+
# Latest.
19+
'latest': {
20+
'confirmed': confirmed['latest'],
21+
'deaths': deaths['latest'],
22+
'recovered': recovered['latest'],
23+
}
24+
})

app/routes/latest.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)