diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..49e16246 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -5,9 +5,9 @@ # Mapping of services to data-sources. DATA_SOURCES = { - "jhu": JhuLocationService(), - "csbs": CSBSLocationService(), - "nyt": NYTLocationService(), + "jhu": JhuLocationService.getInstance(), + "csbs": CSBSLocationService.getInstance(), + "nyt": NYTLocationService.getInstance(), } diff --git a/app/services/location/csbs.py b/app/services/location/csbs.py index 444ebad6..2ea866c3 100644 --- a/app/services/location/csbs.py +++ b/app/services/location/csbs.py @@ -20,6 +20,21 @@ class CSBSLocationService(LocationService): Service for retrieving locations from csbs """ + __instance = None + + @staticmethod + def getInstance(): + if CSBSLocationService.__instance == None: + CSBSLocationService() + return CSBSLocationService.__instance + + def __init__(self): + """ Virtually private constructor. """ + if Singleton.__instance != None: + raise Exception("This class is a singleton!") + else: + Singleton.__instance = self + async def get_all(self): # Get the locations. locations = await get_locations() diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index ebed3960..44311733 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -26,6 +26,21 @@ class JhuLocationService(LocationService): Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19). """ + __instance = None + + @staticmethod + def getInstance(): + if CSBSLocationService.__instance == None: + CSBSLocationService() + return CSBSLocationService.__instance + + def __init__(self): + """ Virtually private constructor. """ + if Singleton.__instance != None: + raise Exception("This class is a singleton!") + else: + Singleton.__instance = self + async def get_all(self): # Get the locations. locations = await get_locations() diff --git a/app/services/location/nyt.py b/app/services/location/nyt.py index 1f25ec34..48c466d9 100644 --- a/app/services/location/nyt.py +++ b/app/services/location/nyt.py @@ -21,6 +21,22 @@ class NYTLocationService(LocationService): Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data). """ + + __instance = None + + @staticmethod + def getInstance(): + if CSBSLocationService.__instance == None: + CSBSLocationService() + return CSBSLocationService.__instance + + def __init__(self): + """ Virtually private constructor. """ + if Singleton.__instance != None: + raise Exception("This class is a singleton!") + else: + Singleton.__instance = self + async def get_all(self): # Get the locations. locations = await get_locations()