Skip to content

Commit 63f6884

Browse files
committed
Make core blocking functions async using aiohttp
1 parent 8b55c16 commit 63f6884

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

app/services/location/csbs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import csv
33
from datetime import datetime
44

5-
import requests
65
from cachetools import TTLCache, cached
76

87
from ...coordinates import Coordinates
98
from ...location.csbs import CSBSLocation
9+
from ...utils import httputils
1010
from . import LocationService
1111

1212

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

2929

3030
@cached(cache=TTLCache(maxsize=1, ttl=3600))
31-
def get_locations():
31+
async def get_locations():
3232
"""
3333
Retrieves county locations; locations are cached for 1 hour
3434
3535
:returns: The locations.
3636
:rtype: dict
3737
"""
38-
request = requests.get(BASE_URL)
39-
text = request.text
38+
async with httputils.client_session.get(BASE_URL) as response:
39+
text = await response.text()
4040

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

app/services/location/jhu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import csv
33
from datetime import datetime
44

5-
import requests
65
from cachetools import TTLCache, cached
76

87
from ...coordinates import Coordinates
98
from ...location import TimelinedLocation
109
from ...timeline import Timeline
1110
from ...utils import countries
1211
from ...utils import date as date_util
12+
from ...utils import httputils
1313
from . import LocationService
1414

1515

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

3838

3939
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
40-
def get_category(category):
40+
async def get_category(category):
4141
"""
4242
Retrieves the data for the provided category. The data is cached for 1 hour.
4343
@@ -52,8 +52,8 @@ def get_category(category):
5252
url = BASE_URL + "time_series_covid19_%s_global.csv" % category
5353

5454
# Request the data
55-
request = requests.get(url)
56-
text = request.text
55+
async with httputils.client_session.get(url) as response:
56+
text = await response.text()
5757

5858
# Parse the CSV.
5959
data = list(csv.DictReader(text.splitlines()))

0 commit comments

Comments
 (0)