Skip to content

Commit

Permalink
Add ListEntry class
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 29, 2024
1 parent 31cd483 commit 9507dd6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions trakt/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ def unfollow(user_name):
yield 'users/{username}/follow'.format(username=slugify(user_name))


@dataclass(frozen=True)
class ListEntry:
id: int
rank: int
listed_at: str
type: str
# data for "type" structure
data: Any
notes: Optional[str] = None

@property
def item(self):
# Poor man's cached_property
if self.type not in self.__dict__:
self.__dict__[self.type] = getattr(self, self.type)

return self.__dict__[self.type]

@property
def movie(self):
data = self.data.copy()
title = data.pop("title")
return Movie(title, **data)

def __getattr__(self, name):
"""
Delegate everything missing to sub-item
"""
return self.item.__getattribute__(name)


@dataclass(frozen=True)
class ListDescription:
name: str
Expand Down

0 comments on commit 9507dd6

Please sign in to comment.