Started refactoring tmdb_api
This commit is contained in:
parent
75d2682458
commit
4d2f386b4f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -130,3 +130,4 @@ dmypy.json
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
lomion.tmdb.mbp
|
lomion.tmdb.mbp
|
||||||
|
test.db
|
||||||
|
|
|
@ -15,9 +15,18 @@ along with tmdb-bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
class Connection():
|
class TmdbApi():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.load_parameters()
|
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):
|
def load_parameters(self):
|
||||||
self.api_key = '51d75c00dc1502dc894b7773ec3e7a15'
|
self.api_key = '51d75c00dc1502dc894b7773ec3e7a15'
|
||||||
|
@ -25,18 +34,16 @@ class Connection():
|
||||||
self.base_url = "https://api.themoviedb.org/3/"
|
self.base_url = "https://api.themoviedb.org/3/"
|
||||||
result = requests.get(self.base_url + 'configuration', params = self.get_apikey()).json()
|
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.base_url_poster = result['images']['base_url'] + result['images']['poster_sizes'][0]
|
||||||
self.valid = False
|
|
||||||
|
|
||||||
self.language = 'de'
|
|
||||||
|
|
||||||
def get_apikey(self):
|
def get_apikey(self):
|
||||||
return { 'api_key' : self.api_key }
|
return { 'api_key' : self.api_key }
|
||||||
|
|
||||||
def request(self, request_uri):
|
def request(self, request_uri, payload : dict = {}):
|
||||||
url = self.base_url + request_uri
|
url = self.base_url + request_uri
|
||||||
payload = self.get_apikey()
|
_payload = self.get_apikey()
|
||||||
payload['language'] = self.language
|
_payload['language'] = self.language
|
||||||
result = requests.get(url, params=payload)
|
_payload.update(payload)
|
||||||
|
result = requests.get(url, params=_payload)
|
||||||
self.valid = True
|
self.valid = True
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -44,11 +51,15 @@ class Connection():
|
||||||
self.language = language
|
self.language = language
|
||||||
|
|
||||||
def get_image_binary(self):
|
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):
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
self.load_parameters()
|
self.load_parameters()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue