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
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Makefile for coronavirus-tracker-api
# ~~~~~~~~~~~~~~~~~~~~~
#
# Combines scripts for common tasks.
#

PYTHON ?= python3

PHONY: all check test

all: test pylint

APP = app
TEST = tests

test:
$(PYTHON) `which py.test` -s -v $(TEST)

lint:
pylint $(APP) || true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ You will need the following things properly installed on your computer.

### Running Tests

* `py.test -s -v tests/`
* `make test`

### Linting

* `pylint app/`
* `make lint`

### Building

Expand Down
8 changes: 7 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from flask import Flask
from flask_cors import CORS

#see PEP396
__version__ = '2.0'

def create_app():
"""
Construct the core application.
Expand All @@ -16,6 +19,9 @@ def create_app():
with app.app_context():
# Import routes.
from . import routes
#register api endpoints
app.register_blueprint(routes.rest_api_v1)
app.register_blueprint(routes.rest_api_v2)

# Return created app.
return app
return app
Empty file added app/config/__init__.py
Empty file.
Empty file added app/data/__init__.py
Empty file.
11 changes: 8 additions & 3 deletions app/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from flask import redirect, current_app as app

# API version 1.
from .v1 import confirmed, deaths, recovered, all
#follow the import order to avoid circular dependency
from flask import Blueprint
rest_api_v1 = Blueprint("rest_api_v1", __name__, url_prefix="")
rest_api_v2 = Blueprint("rest_api_v2", __name__, url_prefix="/v2")

# API version 2.
from .v2 import locations, latest

# API version 1.
from .v1 import confirmed, deaths, recovered, all

# Redirect to project page on index.
@app.route('/')
def index():
return redirect('https://github.com/ExpDev07/coronavirus-tracker-api', 302)
return redirect('https://github.com/ExpDev07/coronavirus-tracker-api', 302)
Empty file added app/routes/v1/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions app/routes/v1/all.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from flask import jsonify
from flask import current_app as app
from ...services.location.jhu import get_category
from ...routes import rest_api_v1

@app.route('/all')
@rest_api_v1.route('/all')
def all():
# Get all the categories.
confirmed = get_category('confirmed')
Expand All @@ -21,4 +22,4 @@ def all():
'deaths': deaths['latest'],
'recovered': recovered['latest'],
}
})
})
5 changes: 3 additions & 2 deletions app/routes/v1/confirmed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import jsonify
from flask import current_app as app
from ...services.location.jhu import get_category
from ...routes import rest_api_v1

@app.route('/confirmed')
@rest_api_v1.route('/confirmed')
def confirmed():
return jsonify(get_category('confirmed'))
return jsonify(get_category('confirmed'))
5 changes: 3 additions & 2 deletions app/routes/v1/deaths.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import jsonify
from flask import current_app as app
from ...services.location.jhu import get_category
from ...routes import rest_api_v1

@app.route('/deaths')
@rest_api_v1.route('/deaths')
def deaths():
return jsonify(get_category('deaths'))
return jsonify(get_category('deaths'))
5 changes: 3 additions & 2 deletions app/routes/v1/recovered.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import jsonify
from flask import current_app as app
from ...services.location.jhu import get_category
from ...routes import rest_api_v1

@app.route('/recovered')
@rest_api_v1.route('/recovered')
def recovered():
return jsonify(get_category('recovered'))
return jsonify(get_category('recovered'))
1 change: 1 addition & 0 deletions app/routes/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 3 additions & 2 deletions app/routes/v2/latest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import jsonify, current_app as app
from ...services import jhu
from ...routes import rest_api_v2

@app.route('/v2/latest')
@rest_api_v2.route('/latest')
def latest():
# Get the serialized version of all the locations.
locations = [ location.serialize() for location in jhu.get_all() ]
Expand All @@ -15,4 +16,4 @@ def latest():
'deaths' : sum(map(lambda latest: latest['deaths'], latest)),
'recovered': sum(map(lambda latest: latest['recovered'], latest)),
}
})
})
5 changes: 3 additions & 2 deletions app/routes/v2/locations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from distutils.util import strtobool
from flask import jsonify, request, current_app as app
from ...services import jhu
from ...routes import rest_api_v2

@app.route('/v2/locations')
@rest_api_v2.route('/locations')
def locations():
# Query parameters.
timelines = strtobool(request.args.get('timelines', default='0'))
Expand All @@ -22,7 +23,7 @@ def locations():
]
})

@app.route('/v2/locations/<int:id>')
@rest_api_v2.route('/locations/<int:id>')
def location(id):
# Query parameters.
timelines = strtobool(request.args.get('timelines', default='1'))
Expand Down
Empty file added app/utils/__init__.py
Empty file.