diff --git a/app/services/location/csbs.py b/app/services/location/csbs.py index dbd8d82d..d0de3837 100644 --- a/app/services/location/csbs.py +++ b/app/services/location/csbs.py @@ -1,5 +1,6 @@ """app.services.location.csbs.py""" import csv +import logging from datetime import datetime from asyncache import cached @@ -39,10 +40,15 @@ async def get_locations(): :returns: The locations. :rtype: dict """ + logger = logging.getLogger("services.location.csbs") + logger.info("Requesting data...") async with httputils.CLIENT_SESSION.get(BASE_URL) as response: text = await response.text() + logger.info("Data received") + data = list(csv.DictReader(text.splitlines())) + logger.info("CSV parsed") locations = [] @@ -77,6 +83,7 @@ async def get_locations(): int(item["Death"] or 0), ) ) + logger.info("Data normalized") # Return the locations. return locations diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index 316de367..39e07ac2 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -1,5 +1,6 @@ """app.services.location.jhu.py""" import csv +import logging from datetime import datetime from asyncache import cached @@ -47,6 +48,7 @@ async def get_category(category): :returns: The data for category. :rtype: dict """ + logger = logging.getLogger("services.location.jhu") # Adhere to category naming standard. category = category.lower() @@ -55,11 +57,15 @@ async def get_category(category): url = BASE_URL + "time_series_covid19_%s_global.csv" % category # Request the data + logger.info("Requesting data...") async with httputils.CLIENT_SESSION.get(url) as response: text = await response.text() + logger.info("Data received") + # Parse the CSV. data = list(csv.DictReader(text.splitlines())) + logger.info("CSV parsed") # The normalized locations. locations = [] @@ -92,6 +98,7 @@ async def get_category(category): "latest": int(latest or 0), } ) + logger.info("Data normalized") # Latest total. latest = sum(map(lambda location: location["latest"], locations)) diff --git a/app/services/location/nyt.py b/app/services/location/nyt.py index 7f73c1de..7f12eb62 100644 --- a/app/services/location/nyt.py +++ b/app/services/location/nyt.py @@ -1,5 +1,6 @@ """app.services.location.nyt.py""" import csv +import logging from datetime import datetime from asyncache import cached @@ -71,13 +72,18 @@ async def get_locations(): :returns: The complete data for US Counties. :rtype: dict """ + logger = logging.getLogger("services.location.nyt") # Request the data. + logger.info("Requesting data...") async with httputils.CLIENT_SESSION.get(BASE_URL) as response: text = await response.text() + logger.info("Data received") + # Parse the CSV. data = list(csv.DictReader(text.splitlines())) + logger.info("CSV parsed") # Group together locations (NYT data ordered by dates not location). grouped_locations = get_grouped_locations_dict(data) @@ -119,5 +125,6 @@ async def get_locations(): }, ) ) + logger.info("Data normalized") return locations