Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
deprecated~=1.2.13
requests-oauthlib>=1.3
requests>=2.25
dataclasses; python_version<"3.7"
14 changes: 12 additions & 2 deletions trakt/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class IdsMixin:

__ids = ['imdb', 'slug', 'tmdb', 'trakt']

def __init__(self):
self._ids = {}
def __init__(self, ids=None):
if ids is None:
ids = {}
self._ids = ids

@property
def ids(self):
Expand Down Expand Up @@ -51,3 +53,11 @@ def tvdb(self):
@property
def tvrage(self):
return self._ids.get('tvrage', None)

@property
def slug(self):
return self._ids.get('slug', None)

@slug.setter
def slug(self, value):
self._ids['slug'] = value
53 changes: 38 additions & 15 deletions trakt/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Interfaces to all of the User objects offered by the Trakt.tv API"""
from collections import namedtuple
from collections import UserDict, namedtuple
from dataclasses import dataclass, field
from typing import Optional, Union

from trakt.core import delete, get, post
from trakt.mixins import IdsMixin
Expand Down Expand Up @@ -62,28 +64,49 @@ def unfollow(user_name):
yield 'users/{username}/follow'.format(username=slugify(user_name))


class UserList(namedtuple('UserList', ['name', 'description', 'privacy',
'share_link', 'type', 'display_numbers',
'allow_comments', 'sort_by',
'sort_how', 'created_at',
'updated_at', 'item_count',
'comment_count', 'likes', 'ids',
'user', 'creator']), IdsMixin):
@dataclass(frozen=True)
class UserListData:
name: str
description: str
privacy: str
share_link: str
type: str
display_numbers: str
allow_comments: str
sort_by: str
sort_how: str
created_at: str
updated_at: str
item_count: str
comment_count: str
likes: str
user: str
creator: str


def DataClassMixin(data_class):
class DataClassMixinClass:
def __init__(self, **kwargs):
self.data = data_class(**kwargs)

def __getattr__(self, item):
return getattr(self.data, item)

return DataClassMixinClass


class UserList(DataClassMixin(UserListData), IdsMixin):
"""A list created by a Trakt.tv :class:`User`"""

def __init__(self, *args, ids=None, **kwargs):
super().__init__()
def __init__(self, ids=None, **kwargs):
super().__init__(**kwargs)
self._ids = ids
self._items = list()
self._items = []

def __iter__(self):
"""Iterate over the items in this user list"""
return self._items.__iter__()

@property
def slug(self):
return self._ids.get('slug', None)

@classmethod
@post
def create(cls, name, creator, description=None, privacy='private',
Expand Down