forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
52 lines (41 loc) · 1.51 KB
/
__init__.py
File metadata and controls
52 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""app.data"""
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService
class DataSourceSingleton:
"""
Singleton class used for storing and retrieving Data Sources
"""
# variable storing the ONLY (if any) DataSourceSingle instance
_instance = None
def __new__(self):
"""
Creates new DataSourceSingleton instance iff one does not exist.
Otherwise, existing instance is used.
Then returns the new/existing instance.
:returns: new/existing instance of DataSourceSingleton object.
:rtype: DataSourceSingleton
"""
if not DataSourceSingleton._instance:
DataSourceSingleton._instance = super(
DataSourceSingleton, self).__new__(self)
# Mapping of services to data-sources.
self._DATA_SOURCES = {
"jhu": JhuLocationService(),
"csbs": CSBSLocationService(),
"nyt": NYTLocationService(),
}
return DataSourceSingleton._instance
def get_data_sources(self):
"""
retrieves and returns _DATA_SOURCES dictionary
"""
return self._DATA_SOURCES
def data_source(source):
"""
Retrieves the provided data-source service.
:returns: The service.
:rtype: LocationService
"""
storedSources = DataSourceSingleton()
return (storedSources.get_data_sources).get(source.lower())