diff --git a/FreeboxMoviePlanner.py b/FreeboxMoviePlanner.py index e26680e..25ee682 100755 --- a/FreeboxMoviePlanner.py +++ b/FreeboxMoviePlanner.py @@ -4,14 +4,14 @@ 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 : - * Prompt the user for movies he wants to record and plan them with the FB API + * Schedule recordings on Freebox using the FB API """ +import datetime import json import logging import requests -import datetime -import tmdbsimple import textwrap +import tmdbsimple from pyfbx.pyfbx import Fbx from bs4 import BeautifulSoup from collections import deque @@ -29,6 +29,7 @@ class Movie: self.good = False self.tmdb_id = '' self.url = '' + self.user_selected = False def __str__(self): return '{}: {} - {} ({})\n TMDB: {} - {}\n @ {}\n {}'.format( @@ -43,8 +44,9 @@ class Movie: ) def __repr__(self): - return "Movie <{} (Ch:{} – R:{})>".format( + return "Movie <{} (D:{} — Ch:{} – R:{})>".format( self.title, + 'Today' if self.day == '' else self.day, self.channel, self.rating ) @@ -53,8 +55,20 @@ class Movie: class TVGuideScraper: TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=free' + def findAllMovies(): + movies = [] + days = deque(['lundi', 'mardi', 'mercredi', + 'jeudi', 'vendredi', 'samedi', 'dimanche']) + offset = datetime.datetime.today().weekday() + days.rotate(-1-offset) + days.appendleft('') + for day in days: + movies += TVGuideScraper._getMovies(day) + logging.info('Found the following movies: {}'.format(movies)) + return movies + @staticmethod - def getMovies(day=''): + def _getMovies(day=''): logging.info('Connecting to {}'.format(TVGuideScraper.TV_GUIDE_URL)) r = requests.get(TVGuideScraper.TV_GUIDE_URL.format(day)) r.raise_for_status() @@ -90,12 +104,12 @@ class TVGuideScraper: class FreeboxMoviePlanner: - def __init__(self): + def __init__(self, movies): 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'] - self.movies = [] + self.movies = movies logging.info('Opening Freebox session') self.freebox = Fbx() @@ -104,10 +118,9 @@ class FreeboxMoviePlanner: token=self.config['freebox-session-token'] ) self.getListOfAvailableChannels() - self.scapeAllMovies() - self.filterUnavailableChannels() + self.excludeUnavailableChannels() self.findMoviesOnTMDB() - self.filterBadRatings() + self.excludeBadRatings() def __repr__(self): result = 'FreeboxMoviePlanner