From e78f71aac83f9dff296ed50afdddbef4e92944d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 2 Jan 2023 21:40:31 +0200 Subject: [PATCH 1/7] Add Watchlist dataclasses --- trakt/users.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/trakt/users.py b/trakt/users.py index a9412a6..3b96a43 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- """Interfaces to all of the User objects offered by the Trakt.tv API""" + from collections import namedtuple +from dataclasses import dataclass +from typing import Any, Optional from trakt.core import delete, get, post from trakt.mixins import IdsMixin @@ -9,8 +12,11 @@ from trakt.tv import TVEpisode, TVSeason, TVShow from trakt.utils import slugify -__author__ = 'Jon Nappi' -__all__ = ['User', 'UserList', 'Request', 'follow', 'get_all_requests', +__author__ = 'Jon Nappi, Elan Ruusamäe' +__all__ = ['User', 'UserList', + 'WatchlistMovieEntry', + 'WatchlistShowEntry', + 'Request', 'follow', 'get_all_requests', 'get_user_settings', 'unfollow'] @@ -26,6 +32,31 @@ def deny(self): yield 'users/requests/{id}'.format(id=self.id) +@dataclass +class WatchlistEntry: + rank: str + id: int + listed_at: str + notes: Optional[str] + type: str + + +@dataclass +class WatchlistMovieEntry(Movie, WatchlistEntry): + movie: Any + + def __post_init__(self): + super().__init__(**self.movie) + + +@dataclass +class WatchlistShowEntry(TVShow, WatchlistEntry): + show: Any + + def __post_init__(self): + super().__init__(**self.show) + + @post def follow(user_name): """Follow a user with *user_name*. If the user has a protected profile, the From acf52bca7f2b9ed37c460d88d70fe0bcc595b53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 2 Jan 2023 22:30:26 +0200 Subject: [PATCH 2/7] Use WatchlistMovieEntry in watchlist_movies --- trakt/users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trakt/users.py b/trakt/users.py index 3b96a43..e73ec31 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -368,8 +368,8 @@ def watchlist_movies(self): ) self._movie_watchlist = [] for movie in data: - mov = movie.pop('movie') - self._movie_watchlist.append(Movie(**mov)) + wl = WatchlistMovieEntry(**movie) + self._movie_watchlist.append(wl) yield self._movie_watchlist yield self._movie_watchlist From 518ec8ac483e96fd6a170b8c1dd04dcafb236644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 2 Jan 2023 22:39:57 +0200 Subject: [PATCH 3/7] Use WatchlistShowEntry in watchlist_shows --- trakt/users.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/trakt/users.py b/trakt/users.py index e73ec31..872d7ff 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -351,9 +351,8 @@ def watchlist_shows(self): ) self._show_watchlist = [] for show in data: - show_data = show.pop('show') - show_data.update(show) - self._show_watchlist.append(TVShow(**show_data)) + wl = WatchlistShowEntry(**show) + self._show_watchlist.append(wl) yield self._show_watchlist yield self._show_watchlist From f8a1529afa210f5531d2ca66dfa8553980d6b61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 2 Jan 2023 23:11:51 +0200 Subject: [PATCH 4/7] Add dataclasses dependency for python 3.6 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index b3cf464..55f5d38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ deprecated~=1.2.13 requests-oauthlib>=1.3 requests>=2.25 +dataclasses; python_version<"3.7" From f8e9ed6c68b7e14d6d172fe463848b6bb779ca83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 2 Jan 2023 23:20:01 +0200 Subject: [PATCH 5/7] Update mock data for watchlist movies/watchlist shows --- tests/mock_data/users.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/mock_data/users.json b/tests/mock_data/users.json index 3e9176e..b555a13 100644 --- a/tests/mock_data/users.json +++ b/tests/mock_data/users.json @@ -527,11 +527,17 @@ "GET": [ { "listed_at":"2014-09-01T09:10:11.000Z", + "rank": 1, + "id": 1, + "notes": null, "type":"movie", "movie":{"title":"TRON: Legacy","year":2010,"ids":{"trakt":1,"slug":"tron-legacy-2010","imdb":"tt1104001","tmdb":20526}} }, { "listed_at":"2014-09-01T09:10:11.000Z", + "rank": 2, + "id": 6, + "notes": null, "type":"movie", "movie":{"title":"The Dark Knight","year":2008,"ids":{"trakt":6,"slug":"the-dark-knight-2008","imdb":"tt0468569","tmdb":155}} } @@ -541,11 +547,17 @@ "GET": [ { "listed_at":"2014-09-01T09:10:11.000Z", + "rank": 1, + "id": 1, + "notes": null, "type":"show", "show":{"title":"Breaking Bad","year":2008,"ids":{"trakt":1,"slug":"breaking-bad","tvdb":81189,"imdb":"tt0903747","tmdb":1396,"tvrage":18164}} }, { "listed_at":"2014-09-01T09:10:11.000Z", + "rank": 2, + "id": 2, + "notes": null, "type":"show", "show":{"title":"The Walking Dead","year":2010,"ids":{"trakt":2,"slug":"the-walking-dead","tvdb":153021,"imdb":"tt1520211","tmdb":1402,"tvrage":null}} } From a7f4b288c2fa118c145f4035cf5d9d6472a855a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 9 Mar 2024 18:17:42 +0200 Subject: [PATCH 6/7] Rank is int --- trakt/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trakt/users.py b/trakt/users.py index 872d7ff..1166e9b 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -34,7 +34,7 @@ def deny(self): @dataclass class WatchlistEntry: - rank: str + rank: int id: int listed_at: str notes: Optional[str] From 37bf8e9ad6f06c0d7d1ab675180e1d628b5ebfa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 9 Mar 2024 18:18:05 +0200 Subject: [PATCH 7/7] Use literal for type --- trakt/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trakt/users.py b/trakt/users.py index 1166e9b..2c8336d 100644 --- a/trakt/users.py +++ b/trakt/users.py @@ -38,7 +38,7 @@ class WatchlistEntry: id: int listed_at: str notes: Optional[str] - type: str + type: Literal["movies", "shows"] @dataclass