Skip to content

Commit a7bf6cc

Browse files
author
ExpDev07
committed
fix
1 parent 8385dfd commit a7bf6cc

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,10 +1,11 @@
1+
from distutils.util import strtobool
12
from flask import jsonify, request, current_app as app
23
from ...services import jhu
34

45
@app.route('/v2/locations')
56
def locations():
67
# Query parameters.
7-
timelines = request.args.get('timelines', type=bool, default=False)
8+
timelines = strtobool(request.args.get('timelines', default='0'))
89
country_code = request.args.get('country_code', type=str)
910

1011
# Retrieve all the locations.
@@ -23,7 +24,10 @@ def locations():
2324

2425
@app.route('/v2/locations/<int:id>')
2526
def location(id):
26-
# Serialize the location with timelines.
27+
# Query parameters.
28+
timelines = strtobool(request.args.get('timelines', default='1'))
29+
30+
# Return serialized location.
2731
return jsonify({
28-
'location': jhu.get(id).serialize(True)
32+
'location': jhu.get(id).serialize(timelines)
2933
})

0 commit comments

Comments
 (0)