From 8d32883c7102bbaee981949713fd1431e1f25975 Mon Sep 17 00:00:00 2001 From: markus Date: Wed, 10 Nov 2021 15:38:28 +0100 Subject: [PATCH] Added vote average --- test_tmdb.py | 9 +++++++++ tmdb/tmdb.py | 2 +- tmdb/tmdb_api.py | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test_tmdb.py b/test_tmdb.py index 212ad47..183022f 100644 --- a/test_tmdb.py +++ b/test_tmdb.py @@ -29,6 +29,14 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): self.assertEqual(movie.valid, True) await movie.close_session() + async def test_vote(self): + movie = Movie() + await movie.load_parameters() + await movie.search_title('Dune') + vote = movie.vote_average + self.assertEqual(vote, 8.0) + await movie.close_session() + async def test_cast(self): movie = Movie() await movie.load_parameters() @@ -204,5 +212,6 @@ class TestTmdbMethods(unittest.IsolatedAsyncioTestCase): await list.close_session() + if __name__ == '__main__': unittest.main() diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index 903c9e4..37f0352 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -44,7 +44,7 @@ class MessageConstructor(): return cast[:-2] def construct_html_message(self) -> str: - html_message = f"""

{escape(self.movie.title)}

+ html_message = f"""

{escape(self.movie.title)} - {str(int(self.movie.vote_average*10))}%

{escape(self.movie.overview)[:self.overview_length]}{self.three_dotts()}

{self.cast()}

Taken from www.themoviedb.org

""" diff --git a/tmdb/tmdb_api.py b/tmdb/tmdb_api.py index 2a5febf..91318ea 100644 --- a/tmdb/tmdb_api.py +++ b/tmdb/tmdb_api.py @@ -145,7 +145,7 @@ class Movie(TmdbApiSingle): self.poster_url = self.base_url_poster + data['poster_path'] self.overview = data['overview'] self.web_url = 'https://www.themoviedb.org/movie/' + str(self.id) - self.vote_average = str(data['vote_average']) + self.vote_average = data['vote_average'] async def query_cast(self, id): data = await self.request('movie/' + str(id) + '/credits') @@ -187,7 +187,7 @@ class TvShow(TmdbApiSingle): self.poster_url = self.base_url_poster + data['poster_path'] self.overview = data['overview'] self.web_url = 'https://www.themoviedb.org/tv/' + str(self.id) - self.vote_average = str(data['vote_average']) + self.vote_average = data['vote_average'] async def query_cast(self): data = await self.request('tv/' + str(self.id) + '/credits')