Add a filter on movie rating, and display movies within 7 days
This commit is contained in:
@ -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
|
||||
|
||||
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
|
||||
@ -34,6 +31,13 @@ class FreeboxMoviePlanner:
|
||||
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=''):
|
||||
logging.info('Connecting to {}'.format(self.TV_GUIDE_URL))
|
||||
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):
|
||||
movie_title = movie.select('.texte_titre a')[0]['title']
|
||||
|
||||
message = 'Found movie: {} - {} ({})'.format(
|
||||
movie_info = '{} - {} ({})'.format(
|
||||
movie_title,
|
||||
movie.select('.texte_cat a')[0].string,
|
||||
channel.select('em')[0].string.replace('Programme ','')
|
||||
)
|
||||
logging.info(message)
|
||||
print(message)
|
||||
logging.info('Found movie: {}'.format(movie_info))
|
||||
|
||||
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)
|
||||
)
|
||||
if tmdb_details:
|
||||
if(
|
||||
float(tmdb_details['vote_average'])
|
||||
< self.config['minimum-rating']
|
||||
):
|
||||
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):
|
||||
logging.info("Searching for '{}' on TMDB".format(movie))
|
||||
@ -75,8 +92,8 @@ class FreeboxMoviePlanner:
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(
|
||||
level=logging.WARNING,
|
||||
level=logging.ERROR,
|
||||
format=' %(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
fmp = FreeboxMoviePlanner()
|
||||
fmp.getMovies()
|
||||
fmp.getAllMovies()
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"tmdb-api":"yourapikey",
|
||||
"tmdb-language":["en","GB"]
|
||||
"tmdb-language":["en","GB"],
|
||||
"minimum-rating":6.5
|
||||
}
|
Reference in New Issue
Block a user