From 6029fb322b7250d320f8854a54c0c37eaef19b7d Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Thu, 1 Feb 2024 12:45:38 +0000 Subject: [PATCH] fix(models.TagRankings): Make name field mandatory --- src/wattpad/models.py | 4 ++-- src/wattpad/wattpad.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wattpad/models.py b/src/wattpad/models.py index aefa541..16cc778 100644 --- a/src/wattpad/models.py +++ b/src/wattpad/models.py @@ -125,8 +125,8 @@ class TagRankingModel(BaseModel): """Represents a Story's Tag Rankings.""" name: str - rank: int - total: int + rank: Optional[int] = None + total: Optional[int] = None class StoryModel(BaseModel): diff --git a/src/wattpad/wattpad.py b/src/wattpad/wattpad.py index 497ea4a..118aa2b 100644 --- a/src/wattpad/wattpad.py +++ b/src/wattpad/wattpad.py @@ -110,6 +110,10 @@ async def fetch_stories(self, include: bool | StoryModelFieldsType = False) -> d include_fields["id"] = True + if "tagRankings" in include_fields: + if type(include_fields["tagRankings"]) is dict: + include_fields["tagRankings"]["name"] = True + url = ( build_url(f"users/{self.data.username}/stories", fields=None) + f"&fields=stories({construct_fields(dict(include_fields))})" # ! The field format for story retrieval differs here. It's /stories?fields=stories(). Compared to the usual /path?fields=. For this reason, we need to manually edit the fields in.