Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ docs/_build/
target/

# OSX Stuff
.DS_Store
.DS_Store

# IntelliJ/Pycharm
.idea/
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
async-asgi-testclient = "*"
bandit = "*"
black = "==19.10b0"
coveralls = "*"
invoke = "*"
isort = "*"
pylint = "*"
pytest = "*"
pytest-asyncio = "*"
pytest-cov = "*"

[packages]
aiohttp = "*"
asyncache = "*"
cachetools = "*"
fastapi = "*"
gunicorn = "*"
Expand Down
128 changes: 124 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .data import data_source
from .router.v1 import V1
from .router.v2 import V2
from .utils.httputils import setup_client_session, teardown_client_session

# ############
# FastAPI App
Expand All @@ -28,6 +29,8 @@
version="2.0.1",
docs_url="/",
redoc_url="/docs",
on_startup=[setup_client_session],
on_shutdown=[teardown_client_session],
)

# #####################
Expand Down
8 changes: 4 additions & 4 deletions app/router/v1/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


@V1.get("/all")
def all(): # pylint: disable=redefined-builtin
async def all(): # pylint: disable=redefined-builtin
"""Get all the categories."""
confirmed = get_category("confirmed")
deaths = get_category("deaths")
recovered = get_category("recovered")
confirmed = await get_category("confirmed")
deaths = await get_category("deaths")
recovered = await get_category("recovered")

return {
# Data.
Expand Down
6 changes: 4 additions & 2 deletions app/router/v1/confirmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


@V1.get("/confirmed")
def confirmed():
async def confirmed():
"""Confirmed cases."""
return get_category("confirmed")
confirmed = await get_category("confirmed")

return confirmed
6 changes: 4 additions & 2 deletions app/router/v1/deaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


@V1.get("/deaths")
def deaths():
async def deaths():
"""Total deaths."""
return get_category("deaths")
deaths = await get_category("deaths")

return deaths
6 changes: 4 additions & 2 deletions app/router/v1/recovered.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


@V1.get("/recovered")
def recovered():
async def recovered():
"""Recovered cases."""
return get_category("recovered")
recovered = await get_category("recovered")

return recovered
4 changes: 2 additions & 2 deletions app/router/v2/latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


@V2.get("/latest", response_model=Latest)
def get_latest(request: Request, source: Sources = "jhu"): # pylint: disable=unused-argument
async def get_latest(request: Request, source: Sources = "jhu"): # pylint: disable=unused-argument
"""
Getting latest amount of total confirmed cases, deaths, and recoveries.
"""
locations = request.state.source.get_all()
locations = await request.state.source.get_all()
return {
"latest": {
"confirmed": sum(map(lambda location: location.confirmed, locations)),
Expand Down
9 changes: 5 additions & 4 deletions app/router/v2/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# pylint: disable=unused-argument,too-many-arguments,redefined-builtin
@V2.get("/locations", response_model=Locations, response_model_exclude_unset=True)
def get_locations(
async def get_locations(
request: Request,
source: Sources = "jhu",
country_code: str = None,
Expand All @@ -28,7 +28,7 @@ def get_locations(
params.pop("timelines", None)

# Retrieve all the locations.
locations = request.state.source.get_all()
locations = await request.state.source.get_all()

# Attempt to filter out locations with properties matching the provided query params.
for key, value in params.items():
Expand Down Expand Up @@ -57,8 +57,9 @@ def get_locations(

# pylint: disable=invalid-name
@V2.get("/locations/{id}", response_model=Location)
def get_location_by_id(request: Request, id: int, source: Sources = "jhu", timelines: bool = True):
async def get_location_by_id(request: Request, id: int, source: Sources = "jhu", timelines: bool = True):
"""
Getting specific location by id.
"""
return {"location": request.state.source.get(id).serialize(timelines)}
location = await request.state.source.get(id)
return {"location": location.serialize(timelines)}
4 changes: 2 additions & 2 deletions app/services/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LocationService(ABC):
"""

@abstractmethod
def get_all(self):
async def get_all(self):
"""
Gets and returns all of the locations.

Expand All @@ -18,7 +18,7 @@ def get_all(self):
raise NotImplementedError

@abstractmethod
def get(self, id): # pylint: disable=redefined-builtin,invalid-name
async def get(self, id): # pylint: disable=redefined-builtin,invalid-name
"""
Gets and returns location with the provided id.

Expand Down
Loading