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
18 changes: 17 additions & 1 deletion app/location/csbs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""app.locations.csbs.py"""
from . import Location

from app.location import nyt

class CSBSLocation(Location):
"""
Expand All @@ -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.
Expand All @@ -41,3 +53,7 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused

# Return the serialized location.
return serialized
'''



106 changes: 106 additions & 0 deletions app/location/nyt.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -30,3 +135,4 @@ def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused

# Return the serialized location.
return serialized
'''
9 changes: 5 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
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
from fastapi.responses import JSONResponse
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
Expand Down