Display all movies with rating and summary
parent
47be13a26b
commit
2dddc56656
|
@ -1,2 +1,3 @@
|
|||
/.project
|
||||
/.pydevproject
|
||||
/config.json
|
||||
|
|
|
@ -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()
|
||||
fmp.getMovies()
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"tmdb-api":"yourapikey",
|
||||
"tmdb-language":["en","GB"]
|
||||
}
|
Loading…
Reference in New Issue