|
6 | 6 | import aiofiles |
7 | 7 | from aiofiles.threadpool.text import AsyncTextIOWrapper |
8 | 8 | from aiohttp import ClientSession |
9 | | -from config import FETCHED_URL_TITLES, HTML_HEADERS |
| 9 | +from config import EXPORT_FILE, HTML_HEADERS |
10 | 10 | from logger import LOGGER |
11 | 11 |
|
12 | 12 | from .data import urls |
|
17 | 17 | async def init_script(): |
18 | 18 | """Initiate script by preparing an output file prior to executing tasks.""" |
19 | 19 | start_time = timer() |
20 | | - async with aiofiles.open(FETCHED_URL_TITLES, mode="w+") as output_file: |
21 | | - await output_file.write("title,url,\n") |
22 | | - await create_and_execute_tasks(output_file) |
23 | | - await output_file.close() |
| 20 | + async with aiofiles.open(EXPORT_FILE, mode="w+") as outfile: |
| 21 | + await outfile.write("title,url,\n") |
| 22 | + await create_and_execute_tasks(outfile) |
| 23 | + await outfile.close() |
24 | 24 | LOGGER.success(f"Executed {__name__} in {time.perf_counter() - start_time:0.2f} seconds.") |
25 | 25 |
|
26 | 26 |
|
27 | | -async def create_and_execute_tasks(output_file: AsyncTextIOWrapper): |
| 27 | +async def create_and_execute_tasks(outfile: AsyncTextIOWrapper): |
28 | 28 | """ |
29 | 29 | Open async HTTP session & execute created tasks. |
30 | 30 |
|
31 | | - :param AsyncTextIOWrapper output_file: Filepath to local .json file to write output to. |
| 31 | + :param AsyncTextIOWrapper outfile: Filepath of local .csv file to write to. |
32 | 32 | """ |
33 | 33 | async with ClientSession(headers=HTML_HEADERS) as session: |
34 | | - task_list = await create_tasks(session, urls, output_file) |
| 34 | + task_list = await create_tasks(session, urls, outfile) |
35 | 35 | inspect_event_loop() |
36 | 36 | await asyncio.gather(*task_list) |
0 commit comments