Skip to content

Commit 82f175b

Browse files
committed
2 parents be71d1d + 14b0d20 commit 82f175b

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ GET /v2/locations?country_code=US
7676

7777
Include timelines.
7878
```http
79-
GET /v2/locations?country_code=US&timelines=true
79+
GET /v2/locations?timelines=1
8080
```
8181

8282
### Getting a specific location (includes timelines by default).
@@ -86,28 +86,32 @@ GET /v2/locations/:id
8686
```json
8787
{
8888
"location": {
89-
"id": 39,
90-
"country": "Norway",
91-
"country_code": "NO",
92-
"province": "",
93-
"coordinates": { },
94-
"latest": { },
95-
"timelines": {
96-
"confirmed": {
97-
"latest": 1463,
98-
"timeline": {
99-
"2020-03-16T00:00:00Z": 1333,
100-
"2020-03-17T00:00:00Z": 1463
101-
}
102-
},
103-
"deaths": { },
104-
"recovered": { }
105-
}
89+
"id": 39,
90+
"country": "Norway",
91+
"country_code": "NO",
92+
"province": "",
93+
"coordinates": { },
94+
"latest": { },
95+
"timelines": {
96+
"confirmed": {
97+
"latest": 1463,
98+
"timeline": {
99+
"2020-03-16T00:00:00Z": 1333,
100+
"2020-03-17T00:00:00Z": 1463
101+
}
102+
},
103+
"deaths": { },
104+
"recovered": { }
106105
}
107106
}
108107
}
109108
```
110109

110+
Exclude timelines.
111+
```http
112+
GET /v2/locations?timelines=0
113+
```
114+
111115
## Data
112116

113117
The data comes from the [2019 Novel Coronavirus (nCoV) Data Repository, provided

app/routes/v2/locations.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from distutils.util import strtobool
12
from flask import jsonify, request, current_app as app
23
from ...services import jhu
34
from ...routes import rest_api_v2
45

56
@rest_api_v2.route('/locations')
67
def locations():
78
# Query parameters.
8-
timelines = request.args.get('timelines', type=bool, default=False)
9+
timelines = strtobool(request.args.get('timelines', default='0'))
910
country_code = request.args.get('country_code', type=str)
1011

1112
# Retrieve all the locations.
@@ -24,7 +25,10 @@ def locations():
2425

2526
@rest_api_v2.route('/locations/<int:id>')
2627
def location(id):
27-
# Serialize the location with timelines.
28+
# Query parameters.
29+
timelines = strtobool(request.args.get('timelines', default='1'))
30+
31+
# Return serialized location.
2832
return jsonify({
29-
'location': jhu.get(id).serialize(True)
33+
'location': jhu.get(id).serialize(timelines)
3034
})

0 commit comments

Comments
 (0)