Browse Source

Refactor: Better decoupling

master
djib 2 years ago
parent
commit
9cf5792d07
  1. 31
      FreeboxMoviePlanner.py

31
FreeboxMoviePlanner.py

@ -48,8 +48,20 @@ class Movie:
class TVGuideScraper:
TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=tnt'
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()
@ -85,12 +97,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
def __repr__(self):
result = 'FreeboxMoviePlanner <Movies:\n'
@ -104,16 +116,6 @@ class FreeboxMoviePlanner:
print(movie)
print()
def scapeAllMovies(self):
days = deque(['lundi', 'mardi', 'mercredi',
'jeudi', 'vendredi', 'samedi', 'dimanche'])
offset = datetime.datetime.today().weekday()
days.rotate(-1-offset)
days.appendleft('')
for day in days:
self.movies += TVGuideScraper.getMovies(day)
logging.info('Found the following movies: {}'.format(self.movies))
def findMoviesOnTMDB(self):
for movie in self.movies:
tmdb_details = self._findMovieOnTMDB(movie.title)
@ -152,8 +154,7 @@ if __name__ == '__main__':
level=logging.INFO,
format=' %(asctime)s - %(levelname)s - %(message)s'
)
fmp = FreeboxMoviePlanner()
fmp.scapeAllMovies()
fmp = FreeboxMoviePlanner(TVGuideScraper.findAllMovies())
fmp.findMoviesOnTMDB()
fmp.filterBadRatings()
fmp.printAllMovies()
Loading…
Cancel
Save