Display all movies with rating and summary
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/.project
|
/.project
|
||||||
/.pydevproject
|
/.pydevproject
|
||||||
|
/config.json
|
||||||
|
58
FreeboxMoviePlanner.py
Normal file → Executable file
58
FreeboxMoviePlanner.py
Normal file → Executable file
@ -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 requests
|
||||||
|
import tmdbsimple
|
||||||
|
import textwrap
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
class FreeboxMoviePlanner:
|
class FreeboxMoviePlanner:
|
||||||
TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=tnt'
|
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
|
@staticmethod
|
||||||
def _tag_is_film(tag):
|
def _tag_is_film(tag):
|
||||||
return (
|
return (
|
||||||
@ -13,18 +35,48 @@ class FreeboxMoviePlanner:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def getMovies(self, day=''):
|
def getMovies(self, day=''):
|
||||||
|
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))
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
html = BeautifulSoup(r.text, 'html.parser')
|
html = BeautifulSoup(r.text, 'html.parser')
|
||||||
for channel in html.select('.bloc_cnt'):
|
for channel in html.select('.bloc_cnt'):
|
||||||
if len(channel.select('em')):
|
if len(channel.select('em')):
|
||||||
for movie in channel.find_all(FreeboxMoviePlanner._tag_is_film):
|
for movie in channel.find_all(FreeboxMoviePlanner._tag_is_film):
|
||||||
print("{} - {} ({})".format(
|
movie_title = movie.select('.texte_titre a')[0]['title']
|
||||||
movie.select('.texte_titre a')[0]['title'],
|
|
||||||
|
message = 'Found movie: {} - {} ({})'.format(
|
||||||
|
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)
|
||||||
|
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__':
|
if __name__ == '__main__':
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.WARNING,
|
||||||
|
format=' %(asctime)s - %(levelname)s - %(message)s'
|
||||||
|
)
|
||||||
fmp = FreeboxMoviePlanner()
|
fmp = FreeboxMoviePlanner()
|
||||||
fmp.getMovies()
|
fmp.getMovies()
|
4
config.template.json
Normal file
4
config.template.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"tmdb-api":"yourapikey",
|
||||||
|
"tmdb-language":["en","GB"]
|
||||||
|
}
|
Reference in New Issue
Block a user