feat(lolz): return last page from get_thread_posts and make post_id optional

This commit is contained in:
2026-07-29 18:43:38 +05:00
parent 68667f669e
commit 953afd385c
+13 -5
View File
@@ -11,7 +11,7 @@ class Lolz:
def __init__(self, token: str):
try:
self.client = Forum(token=token, timeout=15)
self.client.settings.logger.enable()
# self.client.settings.logger.enable()
except:
raise
@@ -22,9 +22,15 @@ class Lolz:
async def get_thread_posts(
self, thread_id: Union[str, int], start_page: int = 1
) -> List[Dict[str, Any]]:
) -> tuple[List[Dict[str, Any]], int]:
"""Fetch all pages starting from start_page.
Returns (posts, last_page) so the caller can resume from last_page
on the next cycle instead of re-fetching from page 1 every time.
"""
all_posts = []
page = start_page
last_page = start_page
while True:
response = await self.client.posts.list(thread_id=thread_id, page=page)
@@ -34,6 +40,7 @@ class Lolz:
break
all_posts.extend(posts)
last_page = page
logger.info(
f"Получено {len(posts)} постов из темы {thread_id} на странице {page}."
)
@@ -46,12 +53,13 @@ class Lolz:
else:
logger.info(f"Постов в теме {thread_id} не найдено.")
return all_posts
return all_posts, last_page
async def get_all_thread_posts(
self, thread_id: Union[str, int]
) -> List[Dict[str, Any]]:
return await self.get_thread_posts(thread_id=thread_id, start_page=1)
posts, _ = await self.get_thread_posts(thread_id=thread_id, start_page=1)
return posts
async def get_post_comments(self, post_id: int) -> List[Dict[str, Any]]:
response = await self.client.posts.comments.list(post_id=post_id)
@@ -60,7 +68,7 @@ class Lolz:
return comments
async def has_comments(
self, post_id: Optional[int], post: Dict[str, Any] = None
self, post_id: Optional[int] = None, post: Dict[str, Any] = None
) -> bool:
if not post:
if not post_id: