Skip to content
Merged
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: 7 additions & 0 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""app.services.location.csbs.py"""
import csv
import logging
from datetime import datetime

from asyncache import cached
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -77,6 +83,7 @@ async def get_locations():
int(item["Death"] or 0),
)
)
logger.info("Data normalized")

# Return the locations.
return locations
7 changes: 7 additions & 0 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""app.services.location.jhu.py"""
import csv
import logging
from datetime import datetime

from asyncache import cached
Expand Down Expand Up @@ -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()
Expand All @@ -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 = []
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""app.services.location.nyt.py"""
import csv
import logging
from datetime import datetime

from asyncache import cached
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -119,5 +125,6 @@ async def get_locations():
},
)
)
logger.info("Data normalized")

return locations