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
2 changes: 1 addition & 1 deletion app/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def data_source(source):
:returns: The service.
:rtype: LocationService
"""
return DATA_SOURCES.get(source.lower())
return LocationServiceAdaptor(DATA_SOURCES.get(source.lower()))
8 changes: 6 additions & 2 deletions app/services/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from abc import ABC, abstractmethod


class LocationService(ABC):
class LocationServiceAdaptor:
"""
Service for retrieving locations.
"""
def __init__(self, source):
self.source = source

@abstractmethod
async def get_all(self):
Expand All @@ -15,6 +17,7 @@ async def get_all(self):
:returns: The locations.
:rtype: List[Location]
"""
return await self.source.get_locations()
raise NotImplementedError

@abstractmethod
Expand All @@ -25,4 +28,5 @@ async def get(self, id): # pylint: disable=redefined-builtin,invalid-name
:returns: The location.
:rtype: Location
"""
raise NotImplementedError
locations = await self.source()
return locations[id]
10 changes: 0 additions & 10 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class CSBSLocationService(LocationService):
Service for retrieving locations from csbs
"""

async def get_all(self):
# Get the locations.
locations = await get_locations()
return locations

async def get(self, loc_id): # pylint: disable=arguments-differ
# Get location at the index equal to the provided id.
locations = await self.get_all()
return locations[loc_id]


# Base URL for fetching data
BASE_URL = "https://facts.csbs.org/covid-19/covid19_county.csv"
Expand Down
12 changes: 0 additions & 12 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ class JhuLocationService(LocationService):
"""
Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19).
"""

async def get_all(self):
# Get the locations.
locations = await get_locations()
return locations

async def get(self, loc_id): # pylint: disable=arguments-differ
# Get location at the index equal to provided id.
locations = await self.get_all()
return locations[loc_id]


# ---------------------------------------------------------------


Expand Down
12 changes: 0 additions & 12 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ class NYTLocationService(LocationService):
"""
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
"""

async def get_all(self):
# Get the locations.
locations = await get_locations()
return locations

async def get(self, loc_id): # pylint: disable=arguments-differ
# Get location at the index equal to provided id.
locations = await self.get_all()
return locations[loc_id]


# ---------------------------------------------------------------


Expand Down