使用TMDB API检索的python对象
如何使用TMDB API检索的一些数据 这就是功能:使用TMDB API检索的python对象,python,api,object,printing,themoviedb-api,Python,Api,Object,Printing,Themoviedb Api,如何使用TMDB API检索的一些数据 这就是功能: class Movies(Core): def __init__(self, title="", limit=False): self.limit = limit self.update_configuration() title = self.escape(title) self.movies = self.getJSON(config['urls']['movie.s
class Movies(Core):
def __init__(self, title="", limit=False):
self.limit = limit
self.update_configuration()
title = self.escape(title)
self.movies = self.getJSON(config['urls']['movie.search'] % (title,str(1)))
pages = self.movies["total_pages"]
if not self.limit:
if int(pages) > 1: #
for i in range(2,int(pages)+1): # Thanks @tBuLi
self.movies["results"].extend(self.getJSON(config['urls']['movie.search'] % (title,str(i)))["results"])
def __iter__(self):
for i in self.movies["results"]:
yield Movie(i["id"])
def get_total_results(self):
if self.limit:
return len(self.movies["results"])
return self.movies["total_results"]
def iter_results(self):
for i in self.movies["results"]:
yield i
电话:
def search_tmdb(title):
tmdb.configure(TMDB_KEY)
movie = tmdb.Movies(title,limit=True)
问题是,如何查看和使用对象电影的结果
对于这个可能很愚蠢的问题,我很抱歉,但我现在要讨论python了看起来您可以执行以下操作:
movies = tmdb.Movies(title,limit=True)
#if you want to deal with Movie objects
for movieresult in movies:
#do something with the Movie result (here I'm just printing it)
print movieresult
#if you want to deal with raw result (not wrapped with a Movie object)
for result in movies.iter_results():
#do something with the raw result
print result
tmdb.Movies(title,limit=True)
创建一个Movies
对象。由于定义了\uu iter\uu
方法,您可以使用for Movies in Movies object
来查看Movies
对象中的结果。您还可以使用movielist=list(movies)
获得Movie
对象的列表 您可以发布从config['url']['movie.search']
返回的json吗?yes@dm03514是这样的:config['url']['movie.search']=”https://api.themoviedb.org/3/search/movie?query=%%s&api_key=%(apikey)s&page=%%s“%(配置)