Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make core blocking functions async using aiohttp
  • Loading branch information
james-gray committed Apr 2, 2020
commit 63f68841602b38bba3fa91a58f39608aae622ce4
8 changes: 4 additions & 4 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import csv
from datetime import datetime

import requests
from cachetools import TTLCache, cached

from ...coordinates import Coordinates
from ...location.csbs import CSBSLocation
from ...utils import httputils
from . import LocationService


Expand All @@ -28,15 +28,15 @@ def get(self, loc_id): # pylint: disable=arguments-differ


@cached(cache=TTLCache(maxsize=1, ttl=3600))
def get_locations():
async def get_locations():
"""
Retrieves county locations; locations are cached for 1 hour

:returns: The locations.
:rtype: dict
"""
request = requests.get(BASE_URL)
text = request.text
async with httputils.client_session.get(BASE_URL) as response:
text = await response.text()

data = list(csv.DictReader(text.splitlines()))

Expand Down
8 changes: 4 additions & 4 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import csv
from datetime import datetime

import requests
from cachetools import TTLCache, cached

from ...coordinates import Coordinates
from ...location import TimelinedLocation
from ...timeline import Timeline
from ...utils import countries
from ...utils import date as date_util
from ...utils import httputils
from . import LocationService


Expand Down Expand Up @@ -37,7 +37,7 @@ def get(self, loc_id): # pylint: disable=arguments-differ


@cached(cache=TTLCache(maxsize=1024, ttl=3600))
def get_category(category):
async def get_category(category):
"""
Retrieves the data for the provided category. The data is cached for 1 hour.

Expand All @@ -52,8 +52,8 @@ def get_category(category):
url = BASE_URL + "time_series_covid19_%s_global.csv" % category

# Request the data
request = requests.get(url)
text = request.text
async with httputils.client_session.get(url) as response:
text = await response.text()

# Parse the CSV.
data = list(csv.DictReader(text.splitlines()))
Expand Down