diff --git a/MangaDexPy/author.py b/MangaDexPy/author.py index ccc88cd..b79cfa9 100644 --- a/MangaDexPy/author.py +++ b/MangaDexPy/author.py @@ -3,11 +3,12 @@ class Author: __slots__ = ("id", "name", "image", "bio", "created_at", "updated_at", "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.name = data["attributes"]["name"] - self.image = data["attributes"]["imageUrl"] - self.bio = data["attributes"]["biography"] - self.created_at = data["attributes"]["createdAt"] - self.updated_at = data["attributes"]["updatedAt"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.name = _attrs.get("name") + self.image = _attrs.get("imageUrl") + self.bio = _attrs.get("biography") + self.created_at = _attrs.get("createdAt") + self.updated_at = _attrs.get("updatedAt") self.client = rel # Dummy assignment for the search helper to work properly. Does not affect the object. self.client = client diff --git a/MangaDexPy/chapter.py b/MangaDexPy/chapter.py index 633059b..a4620d9 100644 --- a/MangaDexPy/chapter.py +++ b/MangaDexPy/chapter.py @@ -4,17 +4,18 @@ class Chapter: "created_at", "updated_at", "parent_manga", "group", "uploader", "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.volume = data["attributes"]["volume"] - self.chapter = data["attributes"]["chapter"] - self.title = data["attributes"]["title"] - self.language = data["attributes"]["translatedLanguage"] - self.hash = data["attributes"]["hash"] - self.pages = data["attributes"]["data"] - self.pages_redux = data["attributes"]["dataSaver"] - self.published_at = data["attributes"]["publishAt"] - self.created_at = data["attributes"]["createdAt"] - self.updated_at = data["attributes"]["updatedAt"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.volume = _attrs.get("volume") + self.chapter = _attrs.get("chapter") + self.title = _attrs.get("title") + self.language = _attrs.get("translatedLanguage") + self.hash = _attrs.get("hash") + self.pages = _attrs.get("data") + self.pages_redux = _attrs.get("dataSaver") + self.published_at = _attrs.get("publishAt") + self.created_at = _attrs.get("createdAt") + self.updated_at = _attrs.get("updatedAt") try: _manga = [x["attributes"] for x in rel if x["type"] == "manga"] from .manga import Manga diff --git a/MangaDexPy/cover.py b/MangaDexPy/cover.py index 6eb6d93..bdb372d 100644 --- a/MangaDexPy/cover.py +++ b/MangaDexPy/cover.py @@ -4,14 +4,15 @@ class Cover: "updated_at", "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.desc = data["attributes"]["description"] - self.volume = data["attributes"]["volume"] - self.file = data["attributes"]["fileName"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.desc = _attrs.get("description") + self.volume = _attrs.get("volume") + self.file = _attrs.get("fileName") self.parent_manga = next((x["id"] for x in rel if x["type"] == "manga"), None) self.url = f"https://uploads.mangadex.org/covers/{self.parent_manga}/{self.file}" self.url_512 = f"{self.url}.512.jpg" self.url_256 = f"{self.url}.256.jpg" - self.created_at = data["attributes"]["createdAt"] - self.updated_at = data["attributes"]["updatedAt"] + self.created_at = _attrs.get("createdAt") + self.updated_at = _attrs.get("updatedAt") self.client = client diff --git a/MangaDexPy/group.py b/MangaDexPy/group.py index 0158ea7..6dd5069 100644 --- a/MangaDexPy/group.py +++ b/MangaDexPy/group.py @@ -6,11 +6,12 @@ class Group: __slots__ = ("id", "name", "leader", "members", "created_at", "updated_at", "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.name = data["attributes"]["name"] - self.leader = User(data["attributes"]["leader"], [], client) - self.members = [User(x, [], client) for x in data["attributes"]["members"]] - self.created_at = data["attributes"]["createdAt"] - self.updated_at = data["attributes"]["updatedAt"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.name = _attrs.get("name") + self.leader = User(_attrs.get("leader"), [], client) + self.members = [User(x, [], client) for x in _attrs.get("members")] + self.created_at = _attrs.get("createdAt") + self.updated_at = _attrs.get("updatedAt") self.client = rel # Dummy assignment for the search helper to work properly. Does not affect the object. self.client = client diff --git a/MangaDexPy/manga.py b/MangaDexPy/manga.py index 2245079..3005d70 100644 --- a/MangaDexPy/manga.py +++ b/MangaDexPy/manga.py @@ -5,22 +5,22 @@ class Manga: "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.title = data["attributes"]["title"] - self.titles = data["attributes"]["altTitles"] - self.desc = data["attributes"]["description"] - self.locked = data["attributes"]["isLocked"] - self.links = data["attributes"]["links"] - self.language = data["attributes"]["originalLanguage"] - self.last_volume = data["attributes"]["lastVolume"] - self.last_chapter = data["attributes"]["lastChapter"] - self.type = data["attributes"]["publicationDemographic"] - self.status = data["attributes"]["status"] - self.year = data["attributes"]["year"] - self.content = data["attributes"]["contentRating"] - self.tags = [MangaTag(x) for x in data["attributes"]["tags"]] - self.created_at = data["attributes"]["createdAt"] - self.updated_at = data["attributes"]["updatedAt"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.title = _attrs.get("title") + self.titles = _attrs.get("altTitles") + self.desc = _attrs.get("description") + self.links = _attrs.get("links") + self.language = _attrs.get("originalLanguage") + self.last_volume = _attrs.get("lastVolume") + self.last_chapter = _attrs.get("lastChapter") + self.type = _attrs.get("publicationDemographic") + self.status = _attrs.get("status") + self.year = _attrs.get("year") + self.content = _attrs.get("contentRating") + self.tags = [MangaTag(x) for x in _attrs.get("tags")] + self.created_at = _attrs.get("createdAt") + self.updated_at = _attrs.get("updatedAt") try: _author = [x["attributes"] for x in rel if x["type"] == "author"] from .author import Author @@ -54,5 +54,5 @@ class MangaTag: __slots__ = ("id", "name") def __init__(self, data): - self.id = data["id"] - self.name = data["attributes"]["name"] + self.id = data.get("id") + self.name = data.get("attributes").get("name") diff --git a/MangaDexPy/user.py b/MangaDexPy/user.py index 79fc3ac..5ac1f6b 100644 --- a/MangaDexPy/user.py +++ b/MangaDexPy/user.py @@ -3,7 +3,8 @@ class User: __slots__ = ("id", "username", "client") def __init__(self, data, rel, client): - self.id = data["id"] - self.username = data["attributes"]["username"] + self.id = data.get("id") + _attrs = data.get("attributes") + self.username = _attrs.get("username") self.client = rel # Dummy assignment for the search helper to work properly. Does not affect the object. self.client = client diff --git a/setup.py b/setup.py index 3071d7b..6192f11 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ packages=[ "MangaDexPy" ], - version='2.0.5', + version='2.0.6', description='An API wrapper for the MangaDexAPIv5.', long_description=long_description, long_description_content_type='text/markdown',