MIL-003: scraping Hacker News #37
@@ -1,10 +1,11 @@
|
|||||||
"""@brief The ports (interfaces) the use cases need from the outside world."""
|
"""@brief The ports (interfaces) the use cases need from the outside world."""
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from typing import TypeAlias
|
||||||
|
|
||||||
from scrape_movies.domain.story import Story
|
from scrape_movies.domain.story import Story
|
||||||
|
|
||||||
## Fetches the HTML text of a page address.
|
## Fetches the HTML text of a page address.
|
||||||
type HtmlFetcher = Callable[[str], str]
|
HtmlFetcher: TypeAlias = Callable[[str], str]
|
||||||
## Turns Hacker News HTML into stories.
|
## Turns Hacker News HTML into stories.
|
||||||
type StoryParser = Callable[[str], list[Story]]
|
StoryParser: TypeAlias = Callable[[str], list[Story]]
|
||||||
|
|||||||
@@ -24,4 +24,8 @@ def top_story(stories: Sequence[Story]) -> Story | None:
|
|||||||
@param stories The stories in page order.
|
@param stories The stories in page order.
|
||||||
@return The first story with the highest score, or None when there are none.
|
@return The first story with the highest score, or None when there are none.
|
||||||
"""
|
"""
|
||||||
return max(stories, key=lambda story: story.upvotes, default=None)
|
best: Story | None = None
|
||||||
|
for story in stories:
|
||||||
|
if best is None or story.upvotes > best.upvotes:
|
||||||
|
best = story
|
||||||
|
return best
|
||||||
|
|||||||
Reference in New Issue
Block a user