From 1b3141b7cb703819c71344341af9dcd203120228 Mon Sep 17 00:00:00 2001 From: Lily Date: Sun, 15 Aug 2021 22:57:12 -0400 Subject: [PATCH] add location factory --- app/data/__init__.py | 14 ++------------ app/services/location/location_factory.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 app/services/location/location_factory.py diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..7f9c83dd 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -1,15 +1,5 @@ """app.data""" -from ..services.location.csbs import CSBSLocationService -from ..services.location.jhu import JhuLocationService -from ..services.location.nyt import NYTLocationService - -# Mapping of services to data-sources. -DATA_SOURCES = { - "jhu": JhuLocationService(), - "csbs": CSBSLocationService(), - "nyt": NYTLocationService(), -} - +from ..services.location.location_factory import LocationFactory def data_source(source): """ @@ -18,4 +8,4 @@ def data_source(source): :returns: The service. :rtype: LocationService """ - return DATA_SOURCES.get(source.lower()) + return LocationFactory.get_location(source) diff --git a/app/services/location/location_factory.py b/app/services/location/location_factory.py new file mode 100644 index 00000000..e1b24bc5 --- /dev/null +++ b/app/services/location/location_factory.py @@ -0,0 +1,12 @@ +"""app.services.location.location_factory.py""" + +class LocationFactory: + def get_location(source): + if source == 'csbs': + return CSBSLocationService() + + elif source == 'nyt' + return NYTLocationService() + + elif source == 'jhu': + return JhuLocationService() \ No newline at end of file