Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 76 lines (62 sloc) 2.158 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
import tmdb, json, time

# genres from http://api.themoviedb.org/2.1/methods/Genres.getList
genres = {}
genres['Action'] = "28"
genres['Adventure'] = "12"
genres['Animation'] = "16"
genres['Comedy'] = "35"
# genres['Crime'] = "80"
genres['Documentary'] = "99"
genres['Drama'] = "99"
genres['Fantasy'] = "14"
# genres['History'] = "36"
genres['Horror'] = "27"
genres['Musical'] = "22"
genres['Science Fiction'] = "878"
# genres['Short'] = "10749"
# genres['Sport'] = "9805"
genres['Suspense'] = "10748"
genres['Thriller'] = "53"
genres['Western'] = "37"

# years = range(2004, 2006)
years = range(1991, 2012)

movies_already = set();

movies = {}

for genre, genre_code in genres.iteritems():
    movies[genre] = {}
    for year in years:
        movies[genre][year] = {}
        time.sleep(1)
        a = tmdb.browse(year=year, genres=genre_code, order_by="rating", order="desc", min_votes=5)
        i = 0
        while i < len(a) and a[i]['name'] in movies_already:
            i += 1
        if i != len(a):
            movie = {}
    
            # grab the cover
            movie['cover'] = ""
            if len(a[i]['images']) > 0:
                try:
                    movie['cover'] = a[i]['images'][0]['cover']
                except KeyError, e:
                    pass

            movieinfo = tmdb.getMovieInfo(a[i]['id'])

            movie['name'] = a[i]['name']
            movie['rating'] = a[i]['rating']
            movie['votes'] = a[i]['votes']

            movie['overview'] = movieinfo['overview']
    
            movie['actors'] = []
            try:
                for actor in movieinfo['cast']['actor']:
                    movie['actors'].append(actor['name'])
            except KeyError, e:
                pass
        
            movie['directors'] = []
            try:
                for director in movieinfo['cast']['director']:
                    movie['directors'].append(director['name'])
            except KeyError, e:
                pass
            
            movies[genre][year] = movie
            movies_already.add(a[i]['name'])
            
print json.dumps(movies, sort_keys=True, indent=4)
Something went wrong with that request. Please try again.