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
7 changes: 2 additions & 5 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ...coordinates import Coordinates
from ...location.csbs import CSBSLocation
from ...utils import httputils
from ...utils.data_urls import DataURLs
from . import LocationService

LOGGER = logging.getLogger("services.location.csbs")
Expand All @@ -31,10 +32,6 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
return locations[loc_id]


# Base URL for fetching data
BASE_URL = "https://facts.csbs.org/covid-19/covid19_county.csv"


@cached(cache=TTLCache(maxsize=1, ttl=1800))
async def get_locations():
"""
Expand All @@ -52,7 +49,7 @@ async def get_locations():
locations = cache_results
else:
LOGGER.info(f"{data_id} shared cache empty")
async with httputils.CLIENT_SESSION.get(BASE_URL) as response:
async with httputils.CLIENT_SESSION.get(DataURLs.CSBS) as response:
text = await response.text()

LOGGER.debug(f"{data_id} Data received")
Expand Down
7 changes: 2 additions & 5 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ...utils import countries
from ...utils import date as date_util
from ...utils import httputils
from ...utils.data_urls import DataURLs
from . import LocationService

LOGGER = logging.getLogger("services.location.jhu")
Expand All @@ -40,10 +41,6 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
# ---------------------------------------------------------------


# Base URL for fetching category.
BASE_URL = "https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/"


@cached(cache=TTLCache(maxsize=4, ttl=1800))
async def get_category(category):
"""
Expand All @@ -64,7 +61,7 @@ async def get_category(category):
else:
LOGGER.info(f"{data_id} shared cache empty")
# URL to request data from.
url = BASE_URL + "time_series_covid19_%s_global.csv" % category
url = DataURLs.JHU + "time_series_covid19_%s_global.csv" % category

# Request the data
LOGGER.info(f"{data_id} Requesting data...")
Expand Down
7 changes: 2 additions & 5 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ...location.nyt import NYTLocation
from ...models import Timeline
from ...utils import httputils
from ...utils.data_urls import DataURLs
from . import LocationService

LOGGER = logging.getLogger("services.location.nyt")
Expand All @@ -35,10 +36,6 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
# ---------------------------------------------------------------


# Base URL for fetching category.
BASE_URL = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"


def get_grouped_locations_dict(data):
"""
Helper function to group history for locations into one dict.
Expand Down Expand Up @@ -85,7 +82,7 @@ async def get_locations():
locations = cache_results
else:
LOGGER.info(f"{data_id} shared cache empty")
async with httputils.CLIENT_SESSION.get(BASE_URL) as response:
async with httputils.CLIENT_SESSION.get(DataURLs.NYT) as response:
text = await response.text()

LOGGER.debug(f"{data_id} Data received")
Expand Down
13 changes: 13 additions & 0 deletions app/utils/data_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""app.utils.data_urls.py"""

import enum


class DataURLs(str, enum.Enum):
"""
URLs available for retrieving data from each possible source.
"""

JHU = "https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/"
CSBS = "https://facts.csbs.org/covid-19/covid19_county.csv"
NYT = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"