Skip to content

Commit 2dc1065

Browse files
committed
make helper functoins local to async_call
1 parent 56f2a91 commit 2dc1065

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

integrations/client/test_delphi_epidata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def test_covidcast_nowcast(self):
472472

473473
self.assertEqual(response, {'result': -2, 'message': 'no results'})
474474

475-
def test_async_call(self):
475+
def test_async_epidata(self):
476476
# insert dummy data
477477
self.cur.execute('''
478478
insert into covidcast values
@@ -490,7 +490,7 @@ def test_async_call(self):
490490
123, 60, 61, 62, 456, 634, 20200414, 0, 1, False)
491491
''')
492492
self.cnx.commit()
493-
test_output = Epidata.async_call([
493+
test_output = Epidata.async_epidata([
494494
{
495495
'source': 'covidcast',
496496
'data_source': 'src',

src/client/delphi_epidata.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -709,29 +709,27 @@ def covidcast_nowcast(
709709
return Epidata._request(params)
710710

711711
@staticmethod
712-
async def async_get(params, session):
713-
"""Helper function to make Epidata GET requests."""
714-
async with session.get(Epidata.BASE_URL, params=params) as response:
715-
return await response.json(), params
716-
717-
@staticmethod
718-
async def async_fetch_epidata(param_combos):
719-
"""Helper function to asynchronously make and aggregate Epidata GET requests."""
720-
tasks = []
721-
async with ClientSession() as session:
722-
for param in param_combos:
723-
task = asyncio.ensure_future(Epidata.async_get(param, session))
724-
tasks.append(task)
725-
responses = await asyncio.gather(*tasks)
726-
return responses
727-
728-
@staticmethod
729-
def async_call(param_list, batch_size=100):
712+
def async_epidata(param_list, batch_size=100):
730713
"""Make asynchronous Epidata calls for a list of parameters."""
714+
async def async_get(params, session):
715+
"""Helper function to make Epidata GET requests."""
716+
async with session.get(Epidata.BASE_URL, params=params) as response:
717+
return await response.json(), params
718+
719+
async def async_make_calls(param_combos):
720+
"""Helper function to asynchronously make and aggregate Epidata GET requests."""
721+
tasks = []
722+
async with ClientSession() as session:
723+
for param in param_combos:
724+
task = asyncio.ensure_future(async_get(param, session))
725+
tasks.append(task)
726+
responses = await asyncio.gather(*tasks)
727+
return responses
728+
731729
batches = [param_list[i:i+batch_size] for i in range(0, len(param_list), batch_size)]
732730
responses = []
733731
for batch in batches:
734732
loop = asyncio.get_event_loop()
735-
future = asyncio.ensure_future(Epidata.async_fetch_epidata(batch))
733+
future = asyncio.ensure_future(async_make_calls(batch))
736734
responses += loop.run_until_complete(future)
737735
return responses

0 commit comments

Comments
 (0)