From 9cf5792d07565aaae2d0f424c9581496f07fa793 Mon Sep 17 00:00:00 2001 From: djib Date: Sun, 6 Oct 2019 01:45:40 +0200 Subject: [PATCH 1/4] Refactor: Better decoupling --- FreeboxMoviePlanner.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index 88bca86..d22e38b 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -48,8 +48,20 @@ class Movie: class TVGuideScraper: TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=tnt' + def findAllMovies(): + movies = [] + days = deque(['lundi', 'mardi', 'mercredi', + 'jeudi', 'vendredi', 'samedi', 'dimanche']) + offset = datetime.datetime.today().weekday() + days.rotate(-1-offset) + days.appendleft('') + for day in days: + movies += TVGuideScraper._getMovies(day) + logging.info('Found the following movies: {}'.format(movies)) + return movies + @staticmethod - def getMovies(day=''): + def _getMovies(day=''): logging.info('Connecting to {}'.format(TVGuideScraper.TV_GUIDE_URL)) r = requests.get(TVGuideScraper.TV_GUIDE_URL.format(day)) r.raise_for_status() @@ -85,12 +97,12 @@ class TVGuideScraper: class FreeboxMoviePlanner: - def __init__(self): + def __init__(self, movies): logging.info('Opening config file: config.json') with open('config.json') as config_file: self.config = json.load(config_file) tmdbsimple.API_KEY = self.config['tmdb-api'] - self.movies = [] + self.movies = movies def __repr__(self): result = 'FreeboxMoviePlanner Date: Sun, 6 Oct 2019 08:40:25 +0200 Subject: [PATCH 2/4] Filter for paid channels --- FreeboxMoviePlanner.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index d22e38b..57e04d9 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -132,9 +132,15 @@ class FreeboxMoviePlanner: movie.url = 'https://www.themoviedb.org/movie/{}?language={}' \ .format(movie.tmdb_id, self.config['tmdb-language']) - def filterBadRatings(self): + def excludeBadRatings(self): self.movies = [movie for movie in self.movies if movie.good] + def excludePaidChannels(self): + paid_channels = ['Canal+'] + self.movies = [ + m for m in self.movies if m.channel not in paid_channels + ] + def _findMovieOnTMDB(self, movie): logging.info("Searching for '{}' on TMDB".format(movie)) search = tmdbsimple.Search() @@ -156,5 +162,6 @@ if __name__ == '__main__': ) fmp = FreeboxMoviePlanner(TVGuideScraper.findAllMovies()) fmp.findMoviesOnTMDB() - fmp.filterBadRatings() + fmp.excludeBadRatings() + fmp.excludePaidChannels() fmp.printAllMovies() From 6587cb245707c44ccff362c89937cb476cf5ab3d Mon Sep 17 00:00:00 2001 From: djib Date: Sun, 6 Oct 2019 23:08:44 +0200 Subject: [PATCH 3/4] Interactive movie selection --- FreeboxMoviePlanner.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index 57e04d9..f3ac795 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -28,6 +28,7 @@ class Movie: self.good = False self.tmdb_id = '' self.url = '' + self.user_selected = False def __str__(self): return '{}: {} - {} ({})\n TMDB: {} - {}\n @ {}\n {}'.format( @@ -42,7 +43,12 @@ class Movie: ) def __repr__(self): - return 'Movie <{}({})>'.format(self.title, self.rating) + return 'Movie <{} ({} :: {} :: {})>'.format( + self.title, + self.day, + self.channel, + self.rating + ) class TVGuideScraper: @@ -112,8 +118,16 @@ class FreeboxMoviePlanner: return result def printAllMovies(self): + for movie in self.movies: + print('{!r}'.format(movie)) + print() + + def askForUserSelection(self): for movie in self.movies: print(movie) + reply = input("Interested? (y/N)") + if reply.upper() == "Y": + movie.user_selected = True print() def findMoviesOnTMDB(self): @@ -141,6 +155,9 @@ class FreeboxMoviePlanner: m for m in self.movies if m.channel not in paid_channels ] + def excludeNotSelected(self): + self.movies = [m for m in self.movies if m.user_selected] + def _findMovieOnTMDB(self, movie): logging.info("Searching for '{}' on TMDB".format(movie)) search = tmdbsimple.Search() @@ -164,4 +181,7 @@ if __name__ == '__main__': fmp.findMoviesOnTMDB() fmp.excludeBadRatings() fmp.excludePaidChannels() + fmp.askForUserSelection() + fmp.excludeNotSelected() + print('\n====== Selected ======\n') fmp.printAllMovies() From c20b24b53c902ff0ad3e21630be7d164d1b384ff Mon Sep 17 00:00:00 2001 From: djib Date: Sun, 6 Oct 2019 23:11:29 +0200 Subject: [PATCH 4/4] Interactive movie selection --- FreeboxMoviePlanner.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index f3ac795..3764379 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -4,7 +4,7 @@ Simple script that extracts information from Télé 7 jours and TMDB to help choosing the movies you want to record with your Freebox Todo : - * Prompt the user for movies he wants to record and plan them with the FB API + * Schedule recordings on Freebox using the FB API """ import json import logging @@ -120,7 +120,6 @@ class FreeboxMoviePlanner: def printAllMovies(self): for movie in self.movies: print('{!r}'.format(movie)) - print() def askForUserSelection(self): for movie in self.movies: