Skip to content

Commit

Permalink
Update modals with .get instead of subscripting
Browse files Browse the repository at this point in the history
  • Loading branch information
Proxymiity committed Jun 13, 2021
1 parent f55a290 commit 86bf2f2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 50 deletions.
13 changes: 7 additions & 6 deletions MangaDexPy/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 12 additions & 11 deletions MangaDexPy/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions MangaDexPy/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions MangaDexPy/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 18 additions & 18 deletions MangaDexPy/manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
5 changes: 3 additions & 2 deletions MangaDexPy/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 86bf2f2

Please sign in to comment.