diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..29274c8a 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -3,19 +3,14 @@ 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(), -} +class data_provide: + dataProvide = {} +def default_set (this): + this.dataProvide['nyt'] = NYTLocationService() + this.dataProvide['csbs'] = CSBSLocationService() + this.dataProvide['jhu'] = JhuLocationService() -def data_source(source): - """ - Retrieves the provided data-source service. +def get_data_provide(this, provide): + return this.dataProvide.get(source.lower()) - :returns: The service. - :rtype: LocationService - """ - return DATA_SOURCES.get(source.lower()) diff --git a/app/main.py b/app/main.py index b9aff949..fc80abe2 100644 --- a/app/main.py +++ b/app/main.py @@ -14,7 +14,7 @@ from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from .config import get_settings -from .data import data_source +from .data import data_provide from .routers import V1, V2 from .utils.httputils import setup_client_session, teardown_client_session @@ -74,7 +74,8 @@ async def add_datasource(request: Request, call_next): Attach the data source to the request.state. """ # Retrieve the datas ource from query param. - source = data_source(request.query_params.get("source", default="jhu")) + source = data_provide() + source.get_data_provide(request.query_params.get("source", default="jhu")) # Abort with 404 if source cannot be found. if not source: diff --git a/app/utils/populations.py b/app/utils/populations.py index c02f15a9..2e4cc189 100644 --- a/app/utils/populations.py +++ b/app/utils/populations.py @@ -7,8 +7,23 @@ import app.io LOGGER = logging.getLogger(__name__) -GEONAMES_URL = "http://api.geonames.org/countryInfoJSON" -GEONAMES_BACKUP_PATH = "geonames_population_mappings.json" +######################################## +#second aggregates pattern +#repost again +###################################### +class GEONAMES + GEONAMES_URL = "" + GEONAMES_BACKUP_PATH = "" + +def defaule_set(self): + self.GEONAMES_URL = "http://api.geonames.org/countryInfoJSON" + self.GEONAMES_BACKUP_PATH = "geonames_population_mappings.json" + +def get_GEONAMES_URL(self): + return self.GEONAME_URL + +def get GEONAME_BACKUP_PATH(self) + return self.GEONAME_BACKUP_PATH # Fetching of the populations. def fetch_populations(save=False):