0

How can i use some data retrieved with TMDB API?

This is the function:

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

And the call:

def search_tmdb(title):
  tmdb.configure(TMDB_KEY)
  movie = tmdb.Movies(title,limit=True)

The question is, how can i see and use the results of the object movie?

I'm sorry for the maybe stupid question but I'm approaching now to python

Travis Bell
  • 204
  • 2
  • 7
masca88
  • 1
  • 1
  • 2
  • could you post the json that is returned from `config['urls']['movie.search']`? – dm03514 Feb 11 '13 at 21:53
  • yes @dm03514 is this: `config['urls']['movie.search'] = "https://api.themoviedb.org/3/search/movie?query=%%s&api_key=%(apikey)s&page=%%s" % (config)` – masca88 Feb 11 '13 at 22:33

1 Answers1

0

looks like you can do something like:

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) creates a Movies object. Since the __iter__ method is defined you can use for movie in moviesobject to go through the results in the Movies object. You could also get a list of Movie objects by using movielist = list(movies).

Stephen
  • 2,365
  • 17
  • 21