Skip to content

Commit 9c8d8f3

Browse files
committed
Add method that returns a threads total pages
1 parent d25b860 commit 9c8d8f3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

loading_sdk/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
API_VERSION = "v1"
44
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
55
EDITORIAL_SORT = ["title"]
6+
POSTS_PER_PAGE = 30
67
FORUM_CATEGORIES = ["games", "other", "texts"]
78
EDITORIAL_POST_TYPES = [
89
"neRegular",

loading_sdk/sync_api/client.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from loading_sdk.settings import (
55
API_URL,
66
API_VERSION,
7-
FORUM_CATEGORIES,
87
EDITORIAL_POST_TYPES,
98
EDITORIAL_SORT,
9+
FORUM_CATEGORIES,
10+
POSTS_PER_PAGE,
1011
USER_AGENT,
1112
)
1213
from loading_sdk.sync_api.extractors import extract_data
@@ -189,7 +190,7 @@ def get_thread(self, thread_id, page=None):
189190
# Doing this checks to make sure it only return data from a page that exists.
190191
if page:
191192
replies = data["posts"][-1]["replies"]
192-
pages = math.ceil(replies / 30)
193+
pages = math.ceil(replies / POSTS_PER_PAGE)
193194

194195
# There is always atleast one page.
195196
if pages == 0:
@@ -483,8 +484,21 @@ def get_socials(self):
483484

484485
return {"code": 200, "message": "OK", "data": data}
485486

486-
def get_total_thread_pages(self):
487-
pass
487+
def get_total_thread_pages(self, thread_id):
488+
response = self.get_thread(thread_id)
489+
490+
if response["code"] != 200:
491+
return response
492+
493+
thread_start = response["data"]["posts"][-1]
494+
replies = thread_start["replies"]
495+
496+
if replies < 1:
497+
replies = 1
498+
499+
pages = math.ceil(replies / POSTS_PER_PAGE)
500+
501+
return pages
488502

489503
def get_total_category_pages(self, category):
490504
if category not in FORUM_CATEGORIES:

0 commit comments

Comments
 (0)