Skip to content

Commit

Permalink
Merge pull request #33 from lasersPew/relations
Browse files Browse the repository at this point in the history
Fixed the parsing of chapter relationships
  • Loading branch information
EMACC99 committed Apr 8, 2024
2 parents 4e6868d + f6fe4a8 commit c89bd41
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions mangadex/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def __init__(self) -> None:
self.chapter: Union[float, None] = None
self.manga_id: str = ""
self.group_id: str = ""
self.group_ids: list[str] = []
self.translatedLanguage: str = ""
self.hash: str = ""
self.data: List[str] = []
Expand Down Expand Up @@ -246,12 +247,19 @@ def chapter_from_dict(cls, data) -> Self:
chapter.publishAt = parse(attributes["publishAt"])
chapter.createdAt = parse(attributes["createdAt"])
chapter.updatedAt = parse(attributes["updatedAt"])
chapter.group_id = data["relationships"][0]["id"]
chapter.manga_id = data["relationships"][1]["id"]
try:
chapter.uploader = data["relationships"][2]["id"]
except IndexError:
pass
for relations in data["relationships"]:
if relations["type"] == "group":
if not chapter.group_id:
chapter.group_id = relations["id"]
else:
if not chapter.group_ids:
chapter.group_ids = [chapter.group_id, relations["id"]]
else:
chapter.group_ids.append(relations["id"])
elif relations["type"] == "manga":
chapter.manga_id = relations["id"]
elif relations["type"] == "user":
chapter.uploader = relations["id"]

return chapter

Expand Down

0 comments on commit c89bd41

Please sign in to comment.