Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ GET /v2/locations?country_code=US

Include timelines.
```http
GET /v2/locations?country_code=US&timelines=true
GET /v2/locations?timelines=1
```

### Getting a specific location (includes timelines by default).
Expand All @@ -86,28 +86,32 @@ GET /v2/locations/:id
```json
{
"location": {
"id": 39,
"country": "Norway",
"country_code": "NO",
"province": "",
"coordinates": { },
"latest": { },
"timelines": {
"confirmed": {
"latest": 1463,
"timeline": {
"2020-03-16T00:00:00Z": 1333,
"2020-03-17T00:00:00Z": 1463
}
},
"deaths": { },
"recovered": { }
}
"id": 39,
"country": "Norway",
"country_code": "NO",
"province": "",
"coordinates": { },
"latest": { },
"timelines": {
"confirmed": {
"latest": 1463,
"timeline": {
"2020-03-16T00:00:00Z": 1333,
"2020-03-17T00:00:00Z": 1463
}
},
"deaths": { },
"recovered": { }
}
}
}
```

Exclude timelines.
```http
GET /v2/locations?timelines=0
```

## Data

The data comes from the [2019 Novel Coronavirus (nCoV) Data Repository, provided
Expand Down
10 changes: 7 additions & 3 deletions app/routes/v2/locations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from distutils.util import strtobool
from flask import jsonify, request, current_app as app
from ...services import jhu

@app.route('/v2/locations')
def locations():
# Query parameters.
timelines = request.args.get('timelines', type=bool, default=False)
timelines = strtobool(request.args.get('timelines', default='0'))
country_code = request.args.get('country_code', type=str)

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

@app.route('/v2/locations/<int:id>')
def location(id):
# Serialize the location with timelines.
# Query parameters.
timelines = strtobool(request.args.get('timelines', default='1'))

# Return serialized location.
return jsonify({
'location': jhu.get(id).serialize(True)
'location': jhu.get(id).serialize(timelines)
})