diff --git a/README.md b/README.md index cec7decc..48d4b137 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 diff --git a/app/routes/v2/locations.py b/app/routes/v2/locations.py index 345f3d3b..540b6303 100644 --- a/app/routes/v2/locations.py +++ b/app/routes/v2/locations.py @@ -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. @@ -23,7 +24,10 @@ def locations(): @app.route('/v2/locations/') 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) })