File tree Expand file tree Collapse file tree 5 files changed +11
-22
lines changed
Expand file tree Collapse file tree 5 files changed +11
-22
lines changed Original file line number Diff line number Diff line change 44from ..utils .populations import country_population
55
66
7-
8- class Locations :
9- def __init__ (self ,locations : list [Location ]):
10- self .locations = locations
11-
12- def add_service (self ,location ):
13- self .locations .append (location )
14-
15- def get_location (self ):
16- return locations
17-
18-
19-
207# pylint: disable=redefined-builtin,invalid-name
218class Location : # pylint: disable=too-many-instance-attributes
229 """
Original file line number Diff line number Diff line change 11"""app.services.location"""
22from abc import ABC , abstractmethod
33
4+ def singleton (cls ):
5+ instances = {}
46
5- class LocationServices :
6- def __init__ (self ,location_services : list [LocationService ]):
7- self .location_services = location_services
7+ def wrapper (* args , ** kwargs ):
8+ if cls not in instances :
9+ instances [cls ] = cls (* args , ** kwargs )
10+ return instances [cls ]
811
9- def add_service (self ,location_service ):
10- self .location_services .append (location_service )
11-
12- def get_service (self ):
13- return location_services
12+ return wrapper
1413
14+ @singleton
1515class LocationService (ABC ):
1616 """
1717 Service for retrieving locations.
Original file line number Diff line number Diff line change 1414
1515LOGGER = logging .getLogger ("services.location.csbs" )
1616
17-
17+ @ singleton
1818class CSBSLocationService (LocationService ):
1919 """
2020 Service for retrieving locations from csbs
Original file line number Diff line number Diff line change 2121PID = os .getpid ()
2222
2323
24+ @singleton
2425class JhuLocationService (LocationService ):
2526 """
2627 Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19).
Original file line number Diff line number Diff line change 1616LOGGER = logging .getLogger ("services.location.nyt" )
1717
1818
19+ @singleton
1920class NYTLocationService (LocationService ):
2021 """
2122 Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
You can’t perform that action at this time.
0 commit comments