realpython / book2-exercises

Book 2 -- Exercises for the book
167 stars 203 forks source link

Rotten Tomatoes "Movie Suggester" — Cannot Get API Key (p. 427 et seq.) #70

Closed stonemirror closed 7 years ago

stonemirror commented 8 years ago

Beginning on p. 427, the exercise to do the "Movie Suggester" application requires a Rotten Tomatoes API key. Unfortunately, Rotten Tomatoes is not making those generally available, you have to apply for one.

From here:

To apply for access to the Rotten Tomatoes API, please submit a proposal form outlining how you would like to use Rotten Tomatoes data. We will review each application to assess whether you are a good candidate based on our updated policies.

Please note that at this time we no longer support unauthorized use of our data (e.g. unofficial projects, non-user facing data integrations).

The note under the example default.py suggests that one "return to the last chapter to find out how to obtain a new [API key]", however that chapter uses the myapifilms.com API, not Rotten Tomatoes'.

Since we're simply pulling the titles of the movies for analysis, the code from the prior chapter will work, but the code here needs to be revised to use the alternate API. I'll post a gist or something when I have the changes worked out.

stonemirror commented 8 years ago

Here's a replacement for default.py which seems to work:

def grab_movies():
    session.m = []
    YOUR_OWN_KEY = 'YOUR_OWN_KEY'
    url = requests.get('http://api.myapifilms.com/imdb/inTheaters?token={}&format=json&language=en-us'.format(YOUR_OWN_KEY))
    binary = url.content
    output = json.loads(binary)
    #
    # Get the titles of the newly-opened movies
    #
    movies = output["data"]["inTheaters"][0]["movies"]
    for movie in movies:
        session.m.append(movie["title"])
    #
    # Get the titles of the other movies playing in theaters
    #
    movies = output["data"]["inTheaters"][1]["movies"]
    for movie in movies:
        session.m.append(movie["title"])
    session.m.sort()
    return TABLE(*[TR(v) for v in session.m]).xml()
mjhea0 commented 8 years ago

Thanks. I am revamping the course now and will add this in.

stonemirror commented 8 years ago

FYI, just verified that this default.py controller works as expected with the templates described in the following pages:

firefoxdevelopereditionscreensnapz171
mjhea0 commented 7 years ago

Updated in v 2.0 of the courses. Coming week of 12/19/2016. https://github.com/realpython/about/blob/master/changelog.csv