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
10 changes: 10 additions & 0 deletions app/services/location/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""app.services.location"""
from abc import ABC, abstractmethod

def singleton(cls):
instances = {}

def wrapper(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]

return wrapper

@singleton
class LocationService(ABC):
"""
Service for retrieving locations.
Expand Down
2 changes: 1 addition & 1 deletion app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

LOGGER = logging.getLogger("services.location.csbs")


@singleton
class CSBSLocationService(LocationService):
"""
Service for retrieving locations from csbs
Expand Down
1 change: 1 addition & 0 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PID = os.getpid()


@singleton
class JhuLocationService(LocationService):
"""
Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19).
Expand Down
1 change: 1 addition & 0 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
LOGGER = logging.getLogger("services.location.nyt")


@singleton
class NYTLocationService(LocationService):
"""
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
Expand Down