diff --git a/app/location/csbs.py b/app/location/csbs.py index 649e8b22..2a360e28 100644 --- a/app/location/csbs.py +++ b/app/location/csbs.py @@ -1,6 +1,6 @@ """app.locations.csbs.py""" from . import Location - +from app.location import nyt class CSBSLocation(Location): """ @@ -25,6 +25,18 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat self.state = state self.county = county + def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument + """ + Serializes the location into a dict. + + :returns: The serialized location. + :rtype: dict + """ + bld = csbs_Serialize_Builder(timelines) + director = Director(bld) + return director.build_product() + +''' def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument """ Serializes the location into a dict. @@ -41,3 +53,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused # Return the serialized location. return serialized +''' + + + diff --git a/app/location/nyt.py b/app/location/nyt.py index ad92212e..872dd15e 100644 --- a/app/location/nyt.py +++ b/app/location/nyt.py @@ -1,6 +1,111 @@ """app.locations.nyt.py""" from . import TimelinedLocation +class Serialize(): # pylint: disable=arguments-differ,unused-argument + + def super_serialized(self, timelines): + serialized = super().serialize(timelines) + return serialized + +# Update with new fields. + def serialized_update(self, serialized): + serialized.update( + {"state": self.state, "county": self.county,} + ) + return serialized + +# Return the serialized location. + def get_serialized(self, serialized): + return serialized + + +class Serialize_Builder: + ser = Serialize() + + def Run_super_serialized(self): + pass + + def Run_serialized_update(self, serialized): + pass + + def Run_get_serialized(self, serialized): + pass + + +class nyt_Serialize_Builder(Serialize_Builder): + def __init__(self, timelines): + self.name = "nyt_ser" + self.nyt_ser = Serialize() + self.timelines = timelines + + def Run_super_serialized(self): + return self.nyt_ser.super_serialized(self.timelines) + + def Run_serialized_update(self, serialized): + return self.nyt_ser.serialized_update(serialized) + + def Run_get_serialized(self, serialized): + return self.nyt_ser.get_serialized() + + +class csbs_Serialize_Builder(Serialize_Builder): + def __init__(self): + self.name = "csbs_ser" + self.csbs_ser = Serialize() + + def Run_super_serialized(self): + return self.csbs_ser.super_serialized() + + def Run_serialized_update(self, serialized): + return self.csbs_ser.serialized_update(serialized) + + def Run_get_serialized(self, serialized): + return self.csbs_ser.get_serialized() + +class Director: + def __init__(self, bld): + self.builder = bld + + def build_product(self): + + if self.builder.name == "nyt_ser": + serialized = self.builder.Run_super_serialized() + update_serialized = self.builder.Run_serialized_update(serialized) + self.builder.Run_get_serialized(update_serialized) +''' + if self.builder.name == "csbs_ser": + self.builder.Run_super_serialized() + self.builder.Run_serialized_update() + self.builder.Run_get_serialized() +''' + + +class NYTLocation(TimelinedLocation): + """ + A NYT (county) Timelinedlocation. + """ + + # pylint: disable=too-many-arguments,redefined-builtin + def __init__(self, id, state, county, coordinates, last_updated, timelines): + super().__init__(id, "US", state, coordinates, last_updated, timelines) + + self.state = state + self.county = county + + def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument + bld = nyt_Serialize_Builder(timelines) + director = Director(bld) + return director.build_product() + + + + + + + +''' + +-------------------------- class NYTLocation(TimelinedLocation): """ @@ -30,3 +135,4 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused # Return the serialized location. return serialized +''' \ No newline at end of file diff --git a/app/main.py b/app/main.py index b9aff949..8e6ae72e 100644 --- a/app/main.py +++ b/app/main.py @@ -6,6 +6,7 @@ import pydantic import sentry_sdk import uvicorn + from fastapi import FastAPI, Request, Response from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware @@ -13,10 +14,10 @@ from scout_apm.async_.starlette import ScoutMiddleware from sentry_sdk.integrations.asgi import SentryAsgiMiddleware -from .config import get_settings -from .data import data_source -from .routers import V1, V2 -from .utils.httputils import setup_client_session, teardown_client_session +from app.config import get_settings +from app.data import data_source +from app.routers import V1, V2 +from app.utils.httputils import setup_client_session, teardown_client_session # ############ # FastAPI App