From 44763c677a176f5a4c797433f5a766e86692e648 Mon Sep 17 00:00:00 2001 From: l3uddz Date: Wed, 13 Mar 2019 22:39:34 +0000 Subject: [PATCH 1/2] Cache: Cache trakt responses for 1 day. --- media/trakt.py | 14 ++++++++++++++ requirements.txt | 1 + 2 files changed, 15 insertions(+) diff --git a/media/trakt.py b/media/trakt.py index e8d2187..59afd8b 100644 --- a/media/trakt.py +++ b/media/trakt.py @@ -3,6 +3,7 @@ import time import backoff import requests +from cashier import cache from helpers.misc import backoff_handler, dict_merge from helpers.trakt import extract_list_user_and_key_from_url @@ -377,6 +378,7 @@ class Trakt: object_name='show', ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_trending_shows(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/shows/trending', @@ -387,6 +389,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_popular_shows(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/shows/popular', @@ -397,6 +400,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_anticipated_shows(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/shows/anticipated', @@ -407,6 +411,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_person_shows(self, person, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/people/%s/shows' % person, @@ -417,6 +422,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None): return self._make_items_request( url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type), @@ -427,6 +433,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_most_watched_shows(self, limit=1000, languages=None, genres=None, most_type=None): return self._make_items_request( url='https://api.trakt.tv/shows/watched/%s' % ('weekly' if not most_type else most_type), @@ -437,6 +444,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_recommended_shows(self, authenticate_user=None, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/recommendations/shows', @@ -482,6 +490,7 @@ class Trakt: object_name='movie', ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_trending_movies(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/movies/trending', @@ -492,6 +501,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_popular_movies(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/movies/popular', @@ -502,6 +512,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_anticipated_movies(self, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/movies/anticipated', @@ -512,6 +523,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_person_movies(self, person, limit=1000, languages=None, genres=None): return self._make_items_request( url='https://api.trakt.tv/people/%s/movies' % person, @@ -522,6 +534,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None): return self._make_items_request( url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type), @@ -532,6 +545,7 @@ class Trakt: genres=genres ) + @cache(cache_file='cache.db', retry_if_blank=True) def get_most_watched_movies(self, limit=1000, languages=None, genres=None, most_type=None): return self._make_items_request( url='https://api.trakt.tv/movies/watched/%s' % ('weekly' if not most_type else most_type), diff --git a/requirements.txt b/requirements.txt index 8066002..1f3ada8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ attrdict==2.0.0 click==6.7 requests~=2.20.0 pyfiglet +cashier~=1.3 \ No newline at end of file From 825429f3a07f0d126a78863f23b31d11bf6bc9fc Mon Sep 17 00:00:00 2001 From: l3uddz Date: Sun, 17 Mar 2019 10:46:37 +0000 Subject: [PATCH 2/2] Traktarr: Should fix the movierating is None bug --- traktarr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traktarr.py b/traktarr.py index 7dc32bd..d24000a 100755 --- a/traktarr.py +++ b/traktarr.py @@ -529,7 +529,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen log.debug("Skipping: %s because it did not have a rating/lacked imdbID", movie['movie']['title']) continue - if rating is None or movieRating >= rating: + if (rating is None or movieRating is None) or movieRating >= rating: log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'], ', '.join(movie['movie']['genres']), movie['movie']['country'].upper())