From 5e4e8aa0588d2f303e11ed5cc8d67e5ee37ce7b9 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Thu, 7 Mar 2024 01:24:33 -0500 Subject: [PATCH] Run linting. --- yellowstone/request/forum_posts.py | 11 +++++++++-- yellowstone/request/forum_threads.py | 2 +- yellowstone/request/site_home_raw.py | 2 +- yellowstone/types.py | 18 +++++++++--------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/yellowstone/request/forum_posts.py b/yellowstone/request/forum_posts.py index 0a2871c..6c69dc9 100644 --- a/yellowstone/request/forum_posts.py +++ b/yellowstone/request/forum_posts.py @@ -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, @@ -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), @@ -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: diff --git a/yellowstone/request/forum_threads.py b/yellowstone/request/forum_threads.py index 6a1621c..2eef20b 100644 --- a/yellowstone/request/forum_threads.py +++ b/yellowstone/request/forum_threads.py @@ -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+)(?:\/.*)?") diff --git a/yellowstone/request/site_home_raw.py b/yellowstone/request/site_home_raw.py index 6bfd599..ffb6b12 100644 --- a/yellowstone/request/site_home_raw.py +++ b/yellowstone/request/site_home_raw.py @@ -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, diff --git a/yellowstone/types.py b/yellowstone/types.py index 0a8e9d9..114f311 100644 --- a/yellowstone/types.py +++ b/yellowstone/types.py @@ -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 @@ -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, @@ -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