diff --git a/.gitignore b/.gitignore index 7b8fdf6..892e881 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,4 @@ dmypy.json .pyre/ lomion.tmdb.mbp +test.db diff --git a/tmdb/tmdb_api.py b/tmdb/tmdb_api.py index c6a82a4..e9529b0 100644 --- a/tmdb/tmdb_api.py +++ b/tmdb/tmdb_api.py @@ -15,9 +15,18 @@ along with tmdb-bot. If not, see . ''' import requests -class Connection(): +class TmdbApi(): def __init__(self): self.load_parameters() + self.title = None + self.id = None + self.poster_url = None + self.overview = None + self.web_url = None + self.vote_average = None + self.language = 'de' + + self.valid = False def load_parameters(self): self.api_key = '51d75c00dc1502dc894b7773ec3e7a15' @@ -25,18 +34,16 @@ class Connection(): self.base_url = "https://api.themoviedb.org/3/" result = requests.get(self.base_url + 'configuration', params = self.get_apikey()).json() self.base_url_poster = result['images']['base_url'] + result['images']['poster_sizes'][0] - self.valid = False - - self.language = 'de' def get_apikey(self): return { 'api_key' : self.api_key } - def request(self, request_uri): + def request(self, request_uri, payload : dict = {}): url = self.base_url + request_uri - payload = self.get_apikey() - payload['language'] = self.language - result = requests.get(url, params=payload) + _payload = self.get_apikey() + _payload['language'] = self.language + _payload.update(payload) + result = requests.get(url, params=_payload) self.valid = True return result @@ -44,11 +51,15 @@ class Connection(): self.language = language def get_image_binary(self): - return requests.get(self.poster_url).content + if self.poster_url: + return requests.get(self.poster_url).content + else: + return None -class Movie(Connection): +class Movie(TmdbApi): def __init__(self): + super().__init__() self.load_parameters() pass