Refactor: Better decoupling
This commit is contained in:
@ -48,8 +48,20 @@ class Movie:
|
|||||||
class TVGuideScraper:
|
class TVGuideScraper:
|
||||||
TV_GUIDE_URL = 'https://www.programme-television.org/{}?bouquet=tnt'
|
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
|
@staticmethod
|
||||||
def getMovies(day=''):
|
def _getMovies(day=''):
|
||||||
logging.info('Connecting to {}'.format(TVGuideScraper.TV_GUIDE_URL))
|
logging.info('Connecting to {}'.format(TVGuideScraper.TV_GUIDE_URL))
|
||||||
r = requests.get(TVGuideScraper.TV_GUIDE_URL.format(day))
|
r = requests.get(TVGuideScraper.TV_GUIDE_URL.format(day))
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
@ -85,12 +97,12 @@ class TVGuideScraper:
|
|||||||
|
|
||||||
|
|
||||||
class FreeboxMoviePlanner:
|
class FreeboxMoviePlanner:
|
||||||
def __init__(self):
|
def __init__(self, movies):
|
||||||
logging.info('Opening config file: config.json')
|
logging.info('Opening config file: config.json')
|
||||||
with open('config.json') as config_file:
|
with open('config.json') as config_file:
|
||||||
self.config = json.load(config_file)
|
self.config = json.load(config_file)
|
||||||
tmdbsimple.API_KEY = self.config['tmdb-api']
|
tmdbsimple.API_KEY = self.config['tmdb-api']
|
||||||
self.movies = []
|
self.movies = movies
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
result = 'FreeboxMoviePlanner <Movies:\n'
|
result = 'FreeboxMoviePlanner <Movies:\n'
|
||||||
@ -104,16 +116,6 @@ class FreeboxMoviePlanner:
|
|||||||
print(movie)
|
print(movie)
|
||||||
print()
|
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):
|
def findMoviesOnTMDB(self):
|
||||||
for movie in self.movies:
|
for movie in self.movies:
|
||||||
tmdb_details = self._findMovieOnTMDB(movie.title)
|
tmdb_details = self._findMovieOnTMDB(movie.title)
|
||||||
@ -152,8 +154,7 @@ if __name__ == '__main__':
|
|||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format=' %(asctime)s - %(levelname)s - %(message)s'
|
format=' %(asctime)s - %(levelname)s - %(message)s'
|
||||||
)
|
)
|
||||||
fmp = FreeboxMoviePlanner()
|
fmp = FreeboxMoviePlanner(TVGuideScraper.findAllMovies())
|
||||||
fmp.scapeAllMovies()
|
|
||||||
fmp.findMoviesOnTMDB()
|
fmp.findMoviesOnTMDB()
|
||||||
fmp.filterBadRatings()
|
fmp.filterBadRatings()
|
||||||
fmp.printAllMovies()
|
fmp.printAllMovies()
|
||||||
|
Reference in New Issue
Block a user