Skip to content
Closed
Changes from 1 commit
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
Next Next commit
Apply factory method to data
  • Loading branch information
antheia-z committed Aug 15, 2021
commit 62e1b4239d56662cdab121c9e0887b1e2beac6f3
29 changes: 23 additions & 6 deletions app/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
"""app.data"""
from ..services.location import LocationService
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService

# Mapping of services to data-sources.
class dataSourceFactory():
def getDataSource():
return LocationService()

class JhuFactory(dataSourceFactory):
def getDataSource():
return JhuLocationService()

class CSBSFactory(dataSourceFactory):
def getDataSource():
return CSBSLocationService()

class NYTFactory(dataSourceFactory):
def getDataSource():
return NYTLcationService()


# Mapping of factories to data-sources.
DATA_SOURCES = {
"jhu": JhuLocationService(),
"csbs": CSBSLocationService(),
"nyt": NYTLocationService(),
"jhu": JhuFactory(),
"csbs": CSBSFactory(),
"nyt": NYTFactory(),
}


def data_source(source):
"""
Retrieves the provided data-source service.

:returns: The service.
:rtype: LocationService
"""
return DATA_SOURCES.get(source.lower())
return DATA_SOURCES.get(source.lower()).getDataSource()