def main():
    assert os.environ["RT_KEY"], "Your Rotten Tomatoes API key should be stored in the RT_KEY env var!"
    rt = RT()                   # NOTE: you should have your API key stored in RT_KEY before this will work

    movies = []
    link_template = ""

    for country in BOX_OFFICE_COUNTRIES:
        print "requesting box office hits for {}".format(country)
        r = rt.lists('movies', 'box_office', limit=LIMIT, country=country)
        movies += r['movies']
        link_template = link_template or r['link_template']

        time.sleep(10)          # respect our API limits!

    # to maintain compatibility with movies.json fields, our top level dict
    # should have the following fields:
    # total (int)
    # movies (list)
    # link_template (string)
    total = len(movies)
    result = {
        "total": total,
        "movies": movies,
        "link_template": link_template,
    }

    with open(OUTPUT_FILE, "w") as f:
        json.dump(result, f, indent=2, sort_keys=True)
Пример #2
0
import config
import media
import my_movie_list
import youtube_search

# Rotten Tomatoes API for Python
# docs: https://github.com/zachwill/rottentomatoes
from rottentomatoes import RT

# initialize a rotten tomatoes instance
rt = RT( config.api_key )

# get a list of movie openings from RT
opening_movies = rt.lists('movies', 'opening')

# iterate through opening movies and create instances of our Movie class for each
movie_collection = []
for mov in opening_movies['movies']:
    # Find youtube trailer
    options = youtube_search.Options( mov['title'] + ' trailer', 1 )
    trailer_id = youtube_search.search(options)

    # Convert cast names to a comma separated list
    cast = ''
    l = mov['abridged_cast'].__len__() - 1
    for i, actor in enumerate( mov['abridged_cast'] ):
        cast += actor['name']
        if i < l:
            cast += ', '

    movie = media.Movie(mov['title'], mov['synopsis'], mov['posters']['thumbnail'], trailer_id, mov['mpaa_rating'], mov['release_dates']['theater'], mov['ratings']['critics_score'], cast)