Skip to content

Commit

Permalink
feat: relations, external, user_updates
Browse files Browse the repository at this point in the history
AUGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
  • Loading branch information
r3tr0ananas committed Nov 25, 2024
1 parent 5fef8d0 commit 7292eb4
Show file tree
Hide file tree
Showing 22 changed files with 372 additions and 62 deletions.
4 changes: 3 additions & 1 deletion anmoku/resources/anime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
from .forum import *
from .pictures import *
from .recommendations import *
from .reviews import *
from .reviews import *
from .relations import *
from .external import *
29 changes: 29 additions & 0 deletions anmoku/resources/anime/external.py
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)
29 changes: 29 additions & 0 deletions anmoku/resources/anime/relations.py
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)
5 changes: 4 additions & 1 deletion anmoku/resources/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
from .news import *
from .forum import *
from .recommendations import *
from .review import *
from .review import *
from .user import *
from .relations import *
from .external import *
26 changes: 26 additions & 0 deletions anmoku/resources/helpers/external.py
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"]
49 changes: 49 additions & 0 deletions anmoku/resources/helpers/relations.py
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]
22 changes: 2 additions & 20 deletions anmoku/resources/helpers/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,16 @@
if TYPE_CHECKING:
from typing import List

from ...typing.jikan.review import UserData, ReactionsData
from ...typing.jikan.review import ReactionsData
from ...typing.jikan import ReviewData

from dataclasses import dataclass, field
from datetime import datetime

from .image import Image
from .user import User

__all__ = ("Review",)

@dataclass
class User():
data: UserData = 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"])

@dataclass
class Reactions():
data: ReactionsData = field(repr = False)
Expand Down
31 changes: 31 additions & 0 deletions anmoku/resources/helpers/user.py
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"])
5 changes: 4 additions & 1 deletion anmoku/resources/manga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
from .forum import *
from .pictures import *
from .recommendations import *
from .reviews import *
from .reviews import *
from .user_updates import *
from .relations import *
from .external import *
29 changes: 29 additions & 0 deletions anmoku/resources/manga/external.py
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)
29 changes: 29 additions & 0 deletions anmoku/resources/manga/relations.py
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)
60 changes: 60 additions & 0 deletions anmoku/resources/manga/user_updates.py
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)
7 changes: 5 additions & 2 deletions anmoku/typing/jikan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from .manga import *
from .news import *
from .forum import *
from .moreinfo import *
from .more_info import *
from .recommendations import *
from .review import *
from .review import *
from .user import *
from .entry import *
from .external import *
Loading

0 comments on commit 7292eb4

Please sign in to comment.