Add a filter on movie rating, and display movies within 7 days

This commit is contained in:
2019-09-24 00:35:57 +02:00
parent 2dddc56656
commit 60b1ba262a
2 changed files with 35 additions and 17 deletions

View File

@ -4,9 +4,6 @@ Simple script that extracts information from Télé 7 jours and TMDB
to help choosing the movies you want to record with your Freebox to help choosing the movies you want to record with your Freebox
Todo : 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 * Prompt the user for movies he wants to record and plan them with the FB API
""" """
import json import json
@ -34,6 +31,13 @@ class FreeboxMoviePlanner:
tag['data-nature']=='films-telefilms' tag['data-nature']=='films-telefilms'
) )
def getAllMovies(self):
days = ['', 'dimanche', 'lundi', 'mardi', 'mercredi',
'jeudi', 'vendredi', 'samedi']
for day in days:
print('=== {}'.format(day.title()))
self.getMovies(day)
def getMovies(self, day=''): def getMovies(self, day=''):
logging.info('Connecting to {}'.format(self.TV_GUIDE_URL)) logging.info('Connecting to {}'.format(self.TV_GUIDE_URL))
r = requests.get(self.TV_GUIDE_URL.format(day)) r = requests.get(self.TV_GUIDE_URL.format(day))
@ -44,24 +48,37 @@ class FreeboxMoviePlanner:
for movie in channel.find_all(FreeboxMoviePlanner._tag_is_film): for movie in channel.find_all(FreeboxMoviePlanner._tag_is_film):
movie_title = movie.select('.texte_titre a')[0]['title'] movie_title = movie.select('.texte_titre a')[0]['title']
message = 'Found movie: {} - {} ({})'.format( movie_info = '{} - {} ({})'.format(
movie_title, movie_title,
movie.select('.texte_cat a')[0].string, movie.select('.texte_cat a')[0].string,
channel.select('em')[0].string.replace('Programme ','') channel.select('em')[0].string.replace('Programme ','')
) )
logging.info(message) logging.info('Found movie: {}'.format(movie_info))
print(message)
tmdb_details = self._getMovieRating(movie_title) tmdb_details = self._getMovieRating(movie_title)
if (tmdb_details): if tmdb_details:
print(" TMDB: {} - {}\n {}".format( if(
tmdb_details['vote_average'], float(tmdb_details['vote_average'])
tmdb_details['original_title'], < self.config['minimum-rating']
'\n '.join(textwrap.wrap( ):
tmdb_details['overview'],75) logging.warning('Bad rating ({}), skipping {}'.format(
) tmdb_details['vote_average'],
movie_title
))
else:
print(movie_info)
print(' TMDB: {} - {}\n {}'.format(
tmdb_details['vote_average'],
tmdb_details['original_title'],
'\n '.join(textwrap.wrap(
tmdb_details['overview'],75)
)
))
print("---")
else:
logging.warning('No TMDB match for {}'.format(
movie_title
)) ))
print("---")
def _getMovieRating(self, movie): def _getMovieRating(self, movie):
logging.info("Searching for '{}' on TMDB".format(movie)) logging.info("Searching for '{}' on TMDB".format(movie))
@ -75,8 +92,8 @@ class FreeboxMoviePlanner:
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig( logging.basicConfig(
level=logging.WARNING, level=logging.ERROR,
format=' %(asctime)s - %(levelname)s - %(message)s' format=' %(asctime)s - %(levelname)s - %(message)s'
) )
fmp = FreeboxMoviePlanner() fmp = FreeboxMoviePlanner()
fmp.getMovies() fmp.getAllMovies()

View File

@ -1,4 +1,5 @@
{ {
"tmdb-api":"yourapikey", "tmdb-api":"yourapikey",
"tmdb-language":["en","GB"] "tmdb-language":["en","GB"],
"minimum-rating":6.5
} }