From 2dddc566567e9df4da950863430b6d6f35cb2ece Mon Sep 17 00:00:00 2001 From: djib Date: Tue, 24 Sep 2019 00:10:50 +0200 Subject: [PATCH] Display all movies with rating and summary --- .gitignore | 1 + FreeboxMoviePlanner.py | 60 +++++++++++++++++++++++++++++++++++++++--- config.template.json | 4 +++ 3 files changed, 61 insertions(+), 4 deletions(-) mode change 100644 => 100755 FreeboxMoviePlanner.py create mode 100644 config.template.json diff --git a/.gitignore b/.gitignore index a2bf2de..8818a1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.project /.pydevproject +/config.json diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py old mode 100644 new mode 100755 index 0c6eda9..2ebe3be --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -1,9 +1,31 @@ +#!/usr/bin/python3 +""" +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 : + * Search for multiple days ahead + * Filter movies above a certain rating + * Sort all movies from best to worst (by day?) + * Prompt the user for movies he wants to record and plan them with the FB API +""" +import json +import logging import requests +import tmdbsimple +import textwrap from bs4 import BeautifulSoup class FreeboxMoviePlanner: TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=tnt' + def __init__(self): + 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'] + + @staticmethod def _tag_is_film(tag): return ( @@ -13,18 +35,48 @@ class FreeboxMoviePlanner: ) def getMovies(self, day=''): + logging.info('Connecting to {}'.format(self.TV_GUIDE_URL)) r = requests.get(self.TV_GUIDE_URL.format(day)) r.raise_for_status() html = BeautifulSoup(r.text, 'html.parser') for channel in html.select('.bloc_cnt'): if len(channel.select('em')): for movie in channel.find_all(FreeboxMoviePlanner._tag_is_film): - print("{} - {} ({})".format( - movie.select('.texte_titre a')[0]['title'], + movie_title = movie.select('.texte_titre a')[0]['title'] + + message = 'Found movie: {} - {} ({})'.format( + movie_title, movie.select('.texte_cat a')[0].string, channel.select('em')[0].string.replace('Programme ','') - )) + ) + logging.info(message) + print(message) + + tmdb_details = self._getMovieRating(movie_title) + if (tmdb_details): + print(" TMDB: {} - {}\n {}".format( + tmdb_details['vote_average'], + tmdb_details['original_title'], + '\n '.join(textwrap.wrap( + tmdb_details['overview'],75) + ) + )) + print("---") + + def _getMovieRating(self, movie): + logging.info("Searching for '{}' on TMDB".format(movie)) + search = tmdbsimple.Search() + search.movie(query=movie, language=self.config['tmdb-language']) + logging.info("Found {}".format(search.results)) + if len(search.results): + return search.results[0] + else: + return [] if __name__ == '__main__': + logging.basicConfig( + level=logging.WARNING, + format=' %(asctime)s - %(levelname)s - %(message)s' + ) fmp = FreeboxMoviePlanner() - fmp.getMovies() \ No newline at end of file + fmp.getMovies() diff --git a/config.template.json b/config.template.json new file mode 100644 index 0000000..3bb1c61 --- /dev/null +++ b/config.template.json @@ -0,0 +1,4 @@ +{ + "tmdb-api":"yourapikey", + "tmdb-language":["en","GB"] +} \ No newline at end of file