Skip to content

Commit e83e17e

Browse files
committed
parser.py
1 parent 35610f6 commit e83e17e

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

asyncio_tutorial/part_II_aiohttp_aiofiles/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
from asyncio_tutorial.logger import LOGGER
77
from config import EXPORT_DIR, HTML_HEADERS
8-
from data import parse_urls
8+
from data import urls
99

1010
from .tasks import create_tasks
1111

1212

1313
async def aiohttp_aiofiles_tutorial():
1414
"""Open async HTTP session & execute created tasks."""
1515
LOGGER.info(f"Asyncio tutorial Part II: HTTP Requests with Aiohttp & Aiofiles.")
16-
urls = parse_urls()
1716
async with ClientSession(headers=HTML_HEADERS) as session:
1817
tasks = await create_tasks(session, urls, EXPORT_DIR)
1918
await asyncio.gather(*tasks)

data/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
"""Parse data from local files."""
22
from .parser import parse_urls
3+
from config import CSV_FILEPATH
4+
5+
6+
urls = parse_urls(CSV_FILEPATH)

data/parser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
import csv
33
from typing import List
44

5-
from config import CSV_FILEPATH
65

7-
8-
def parse_urls() -> List[str]:
6+
def parse_urls(filepath: str) -> List[str]:
97
"""
108
Parse a single-column CSV into a Python list of URLs.
119
1210
:returns: List[str]
1311
"""
1412
urls = []
15-
with open(CSV_FILEPATH, newline="") as f:
13+
with open(filepath, newline="") as f:
1614
reader = csv.reader(f)
1715
for line in reader:
1816
urls.append(line[0])

data/tests/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import pytest
22
from typing import List
33

4-
from data.parser import parse_urls
4+
from data.parser import urls
55

66

77
def test_parse_urls():
8-
urls = parse_urls()
8+
99

1010
assert(type(urls)) == List[str]

0 commit comments

Comments
 (0)