Started refactoring tmdb_api

This commit is contained in:
lomion 2020-06-23 17:47:37 +02:00
parent 75d2682458
commit 4d2f386b4f
2 changed files with 22 additions and 10 deletions

1
.gitignore vendored
View file

@ -130,3 +130,4 @@ dmypy.json
.pyre/
lomion.tmdb.mbp
test.db

View file

@ -15,9 +15,18 @@ along with tmdb-bot. If not, see <https://www.gnu.org/licenses/>.
'''
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):
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