-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: relations, external, user_updates
AUGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- Loading branch information
1 parent
5fef8d0
commit 7292eb4
Showing
22 changed files
with
372 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ...typing.jikan import ( | ||
ExternalSourceData, | ||
JikanResponseData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from ..base import JikanResource | ||
from ..helpers import ExternalSource | ||
|
||
__all__ = ( | ||
"AnimeExternal", | ||
) | ||
|
||
@dataclass | ||
class AnimeExternal(JikanResource): | ||
_get_endpoint = "/anime/{id}/external" | ||
|
||
data: JikanResponseData[List[ExternalSourceData]] = field(repr = False) | ||
|
||
def __iter__(self): | ||
for relation in self.data["data"]: | ||
yield ExternalSource(relation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ...typing.jikan import ( | ||
RelationData, | ||
JikanResponseData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from ..base import JikanResource | ||
from ..helpers import Relation | ||
|
||
__all__ = ( | ||
"AnimeRelations", | ||
) | ||
|
||
@dataclass | ||
class AnimeRelations(JikanResource): | ||
_get_endpoint = "/anime/{id}/relations" | ||
|
||
data: JikanResponseData[List[RelationData]] = field(repr = False) | ||
|
||
def __iter__(self): | ||
for relation in self.data["data"]: | ||
yield Relation(relation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from ...typing.jikan import ( | ||
ExternalSourceData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
__all__ = ( | ||
"ExternalSource", | ||
) | ||
|
||
@dataclass | ||
class ExternalSource(): | ||
data: ExternalSourceData = field(repr = False) | ||
|
||
name: str = field(init = False) | ||
url: str = field(init = False) | ||
|
||
def __post_init__(self): | ||
external = self.data | ||
|
||
self.name = external["name"] | ||
self.url = external["url"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ...typing.jikan import ( | ||
RelationData, | ||
EntryData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
__all__ = ( | ||
"Entry", | ||
"Relation", | ||
) | ||
|
||
@dataclass | ||
class Entry(): | ||
data: EntryData = field(repr = False) | ||
|
||
id: int = field(init = False) | ||
type: str = field(init = False) | ||
name: str = field(init = False) | ||
url: str = field(init = False) | ||
|
||
def __post_init__(self): | ||
entry = self.data | ||
|
||
self.id = entry["mal_id"] | ||
self.type = entry["type"] | ||
self.name = entry["name"] | ||
self.url = entry["url"] | ||
|
||
@dataclass | ||
class Relation(): | ||
data: RelationData = field(repr = False) | ||
|
||
relation: str = field(init = False) | ||
|
||
entries: List[Entry] = field(init = False) | ||
|
||
def __post_init__(self): | ||
self.relation = self.data["relation"] | ||
|
||
entries = self.data["entry"] | ||
|
||
self.entries = [Entry(entry) for entry in entries] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from ...typing.jikan import PartialUserData | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from .image import Image | ||
|
||
__all__ = ( | ||
"User", | ||
) | ||
|
||
@dataclass | ||
class User(): | ||
data: PartialUserData = field(repr = False) | ||
|
||
username: str = field(init = False) | ||
"""The MyAnimeList Username of the reviewer.""" | ||
url: str = field(init = False) | ||
"""The MyAnimeList Profile URL of the reviewer.""" | ||
image: Image = field(init = False) | ||
"""The Profile Picture of the reviewer.""" | ||
|
||
def __post_init__(self): | ||
user = self.data | ||
|
||
self.username = user["username"] | ||
self.url = user["url"] | ||
self.image = Image(user["images"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ...typing.jikan import ( | ||
ExternalSourceData, | ||
JikanResponseData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from ..base import JikanResource | ||
from ..helpers import ExternalSource | ||
|
||
__all__ = ( | ||
"MangaExternal", | ||
) | ||
|
||
@dataclass | ||
class MangaExternal(JikanResource): | ||
_get_endpoint = "/manga/{id}/external" | ||
|
||
data: JikanResponseData[List[ExternalSourceData]] = field(repr = False) | ||
|
||
def __iter__(self): | ||
for relation in self.data["data"]: | ||
yield ExternalSource(relation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List | ||
|
||
from ...typing.jikan import ( | ||
RelationData, | ||
JikanResponseData, | ||
) | ||
|
||
from dataclasses import dataclass, field | ||
|
||
from ..base import JikanResource | ||
from ..helpers import Relation | ||
|
||
__all__ = ( | ||
"MangaRelations", | ||
) | ||
|
||
@dataclass | ||
class MangaRelations(JikanResource): | ||
_get_endpoint = "/manga/{id}/relations" | ||
|
||
data: JikanResponseData[List[RelationData]] = field(repr = False) | ||
|
||
def __iter__(self): | ||
for relation in self.data["data"]: | ||
yield Relation(relation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING, List | ||
|
||
if TYPE_CHECKING: | ||
from ...typing.jikan.manga import MangaUserUpdatesData | ||
from ...typing.jikan.api import JikanResponseData | ||
|
||
from dataclasses import dataclass, field | ||
from datetime import datetime | ||
|
||
from ..base import JikanResource | ||
from ..helpers import User | ||
|
||
__all__ = ( | ||
"MangaUserUpdates", | ||
) | ||
|
||
@dataclass | ||
class UserUpdate(): | ||
data: MangaUserUpdatesData | ||
|
||
user: User = field(init = False) | ||
"""The user in this update.""" | ||
score: int = field(init = False) | ||
"""The score the user gave the manga.""" | ||
status: str = field(init = False) | ||
"""The status, e.g. `Completed`.""" | ||
volumes_read: int = field(init = False) | ||
"""The amount of volumes read.""" | ||
volumes_total: int = field(init = False) | ||
"""The amount of total volumes.""" | ||
chapters_read: int = field(init = False) | ||
"""The amount of chapters read.""" | ||
chapters_total: int = field(init = False) | ||
"""The amount of total chapters.""" | ||
date: datetime = field(init = False) | ||
"""When the update was made.""" | ||
|
||
def __post_init__(self): | ||
update = self.data | ||
|
||
self.user = User(update["user"]) | ||
self.score = update["score"] | ||
self.status = update["status"] | ||
self.volumes_read = update["volumes_read"] | ||
self.volumes_total = update["volumes_total"] | ||
self.chapters_read = update["chapters_read"] | ||
self.chapters_total = update["chapters_total"] | ||
self.date = datetime.fromisoformat(update["date"]) | ||
|
||
@dataclass | ||
class MangaUserUpdates(JikanResource): | ||
_get_endpoint = "/manga/{id}/userupdates" | ||
|
||
data: JikanResponseData[List[MangaUserUpdatesData]] = field(repr = False) | ||
|
||
def __iter__(self): | ||
|
||
for update in self.data["data"]: | ||
yield UserUpdate(update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.