From ac0ebec6c6c366bd203c8745e023cd9e518458af Mon Sep 17 00:00:00 2001 From: lou liu Date: Sun, 18 Jul 2021 18:10:35 +0800 Subject: [PATCH 1/6] Commit description --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b9aff949..8f710e08 100644 --- a/app/main.py +++ b/app/main.py @@ -19,7 +19,7 @@ from .utils.httputils import setup_client_session, teardown_client_session # ############ -# FastAPI App +# FastAPI App Do some change to fix # ############ LOGGER = logging.getLogger("api") From 999f0c66a85a9d3f4c3a0706520bedc91844f317 Mon Sep 17 00:00:00 2001 From: lou liu Date: Tue, 20 Jul 2021 13:28:31 +0800 Subject: [PATCH 2/6] Commit description --- app/data/__init__.py | 21 ++++++++------------- app/main.py | 7 ++++--- 2 files changed, 12 insertions(+), 16 deletions(-) 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 8f710e08..fc80abe2 100644 --- a/app/main.py +++ b/app/main.py @@ -14,12 +14,12 @@ 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 # ############ -# FastAPI App Do some change to fix +# FastAPI App # ############ LOGGER = logging.getLogger("api") @@ -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: From adb543e03deeedd9be6c997fa655e8b685837adb Mon Sep 17 00:00:00 2001 From: lou liu Date: Tue, 20 Jul 2021 13:54:29 +0800 Subject: [PATCH 3/6] second --- app/utils/populations.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/utils/populations.py b/app/utils/populations.py index c02f15a9..26832582 100644 --- a/app/utils/populations.py +++ b/app/utils/populations.py @@ -10,6 +10,20 @@ GEONAMES_URL = "http://api.geonames.org/countryInfoJSON" GEONAMES_BACKUP_PATH = "geonames_population_mappings.json" +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): """ From 92415620f584f4ecf66d34b5ae688636f363f7dc Mon Sep 17 00:00:00 2001 From: lou liu Date: Tue, 20 Jul 2021 13:57:40 +0800 Subject: [PATCH 4/6] Commit decription --- app/utils/populations.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/utils/populations.py b/app/utils/populations.py index 26832582..a1de8998 100644 --- a/app/utils/populations.py +++ b/app/utils/populations.py @@ -7,9 +7,6 @@ import app.io LOGGER = logging.getLogger(__name__) -GEONAMES_URL = "http://api.geonames.org/countryInfoJSON" -GEONAMES_BACKUP_PATH = "geonames_population_mappings.json" - class GEONAMES GEONAMES_URL = "" GEONAMES_BACKUP_PATH = "" From c912d877c3caf46e75ca739307552ccaf4f645fa Mon Sep 17 00:00:00 2001 From: lou liu Date: Tue, 20 Jul 2021 14:10:55 +0800 Subject: [PATCH 5/6] repost for lab --- app/utils/populations.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/utils/populations.py b/app/utils/populations.py index a1de8998..6ca4d522 100644 --- a/app/utils/populations.py +++ b/app/utils/populations.py @@ -7,6 +7,10 @@ import app.io LOGGER = logging.getLogger(__name__) +######################################## +#second aggregates pattern +#repost +###################################### class GEONAMES GEONAMES_URL = "" GEONAMES_BACKUP_PATH = "" From eeab6af25e6147789eb7b70170a6af19dad69a0e Mon Sep 17 00:00:00 2001 From: lou liu Date: Tue, 20 Jul 2021 14:16:29 +0800 Subject: [PATCH 6/6] repost the lab8 --- app/utils/populations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/populations.py b/app/utils/populations.py index 6ca4d522..2e4cc189 100644 --- a/app/utils/populations.py +++ b/app/utils/populations.py @@ -9,7 +9,7 @@ LOGGER = logging.getLogger(__name__) ######################################## #second aggregates pattern -#repost +#repost again ###################################### class GEONAMES GEONAMES_URL = ""