Skip to content

Commit

Permalink
Run linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Mar 7, 2024
1 parent 115a351 commit 5e4e8aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
11 changes: 9 additions & 2 deletions yellowstone/request/forum_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def get(
source = f"forum category {category_id} thread {thread_id}"

# Get header information
breadcrumbs = assert_is_tag(soup.find("div", class_="forum-breadcrumbs"), "breadcrumbs")
breadcrumbs = assert_is_tag(
soup.find("div", class_="forum-breadcrumbs"),
"breadcrumbs",
)
_, category_anchor = breadcrumbs.find_all("a")
category_id_ex = regex_extract_int(
source,
Expand All @@ -83,7 +86,10 @@ def get(
# However we already got that above so it's not necessary here.

# Iterate through posts
container = assert_is_tag(soup.find(id="thread-container-posts"), "thread container")
container = assert_is_tag(
soup.find(id="thread-container-posts"),
"thread container",
)
return list(
map(
lambda post: process_post(source, post),
Expand All @@ -94,6 +100,7 @@ def get(
# we don't need to be *that* efficient, just group
# by thread, so if a thread has < 10 posts just put
# them in one request and that's that
_ = thread_title


def process_post(source: str, post: Tag) -> ForumPostData:
Expand Down
2 changes: 1 addition & 1 deletion yellowstone/request/forum_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
make_soup,
regex_extract_int,
)
from ..types import ForumLastPostData, ForumPostUser, UserModuleData
from ..types import ForumLastPostData, ForumPostUser
from ..wikidot import Wikidot

LAST_THREAD_ID = re.compile(r"/forum/t-(\d+)(?:\/.*)?")
Expand Down
2 changes: 1 addition & 1 deletion yellowstone/request/site_home_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional

from bs4 import BeautifulSoup, Tag
from bs4 import BeautifulSoup

from ..scraper import (
download_html,
Expand Down
18 changes: 9 additions & 9 deletions yellowstone/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dataclasses import dataclass
from datetime import datetime
from typing import Any, TypeVar, Union
from typing import Any, Union

from bs4 import Tag

Expand Down Expand Up @@ -40,14 +40,6 @@ def is_system(self) -> bool:
return self.name.casefold() == "wikidot"


@dataclass
class ForumLastPostData:
posted_time: datetime
posted_user: ForumPostUser
thread_id: int
post_id: int


Json = Union[None, int, float, str, list["Json"], dict[str, "Json"]]
ForumPostUser = Union[
UserModuleData,
Expand All @@ -57,6 +49,14 @@ class ForumLastPostData:
]


@dataclass
class ForumLastPostData:
posted_time: datetime
posted_user: ForumPostUser
thread_id: int
post_id: int


def assert_is_tag(object: Any, name: str = "Object") -> Tag:
assert isinstance(object, Tag), f"{name} is not an HTML entity"
return object

0 comments on commit 5e4e8aa

Please sign in to comment.