<jupyter_start><jupyter_text>Exercise 2Add the specified code for each code cell, running the cells _in order_. In this exercise, you'll practice working with a data API: specifically, the [New York Times API](https://developer.nytimes.com/) for movie reviews. To learn more about the API, see the [developer console](https://developer.nytimes.com/movie_reviews_v2.json). You will need to register with the NYT site at **** in order to get an API Key. Fill out the form (you can use fake information and a single-use email if you wish). Under "API" select **"Movie Reviews API"** (and note other APIs available for future projects)! The API key should be emailed to you once you sign up.In order to utilize this key in your script, create a **separate* Python script called `apikey.py` inside this directory (the one with this Jupyter notebook). Assign the key that was emailed to you to a variable:```pythonnyt_apikey = "<KEY>"```You should also modify the included `.gitignore` file inside the directory to list your `apikey.py` script so that it doesn't get committed! Import your `nyt_apikey` variable from your `apikey` script. Print out the _length_ of the key (but not the key itself!) to confirm that it has been imported.<jupyter_code>##Update "developer console" link above: https://developer.nytimes.com/docs/movie-reviews-api/1/overview

##Try running without first, get the error, 
## Call out, need to actually create the file. Don't do it manually
## "use command line!" then in the command line demonstrate: 

#echo "nyt_apikey = '...akikey...'" > apikey.py


##article on hiding your gitignore file: http://www.blacktechdiva.com/hide-api-keys/
from apikey import nyt_apikey
print(len(nyt_apikey))<jupyter_output>32<jupyter_text>Create a variable **`movie_name`** that contains the name of a movie of your choice.<jupyter_code>movie_name = "Reservoir Dogs"<jupyter_output><empty_output><jupyter_text>Construct an HTTP request to search for reviews for that movie. - The base URI is `https://api.nytimes.com/svc/movies/v2/` - The resource is `reviews/search.json`- Your request will need two query parameters: the movie name as the `query` and YOUR api key as the `api-key` parameter.Then send the HTTP request and output its `status_code` to demonstrate that it worked.<jupyter_code>import requests
base_uri = "https://api.nytimes.com/svc/movies/v2/"
resource = "reviews/search.json"
query_params = {'query': movie_name, 'api-key': nyt_apikey}

response = requests.get(base_uri + resource, params = query_params)
response.status_code<jupyter_output><empty_output><jupyter_text>Access the response JSON content as a Python data structure, saving it as a variable (e.g., `data`). Use the `type()` function to determine if the content is a list or a dictionary.<jupyter_code>data = response.json()
type(data)<jupyter_output><empty_output><jupyter_text>Since the `data` is a dictionary, check its keys and identify the one with the value of interest&mdash;where is the _list of dictionaries_ with movie review data? Store the first item from that list in a variable `movie_review` and print it out.<jupyter_code>data.keys()
movie_review = data['results'][0]
print(movie_review)<jupyter_output>{'display_title': 'Reservoir Dogs', 'mpaa_rating': '', 'critics_pick': 0, 'byline': '<NAME>', 'headline': 'RESERVOIR DOGS (MOVIE)', 'summary_short': 'Crooks regroup at warehouse after heist. Brutal and dazzling, via Tarantino.', 'publication_date': '1992-10-23', 'opening_date': None, 'date_updated': '2017-11-02 04:16:11', 'link': {'type': 'article', 'url': 'http://www.nytimes.com/1992/10/23/movies/review-film-a-caper-goes-wrong-resoundingly.html', 'suggested_link_text': 'Read the New York Times Review of Reservoir Dogs'}, 'multimedia': None}<jupyter_text>Print out the _headline_, _short summary_, and a _link to the full article_ of the `movie_review`.<jupyter_code>print(movie_review['headline'])
print(movie_review['summary_short'])
print(movie_review['link']['url'])<jupyter_output>RESERVOIR DOGS (MOVIE)
Crooks regroup at warehouse after heist. Brutal and dazzling, via Tarantino.
http://www.nytimes.com/1992/10/23/movies/review-film-a-caper-goes-wrong-resoundingly.html
{'fraction_non_alphanumeric': 0.11180124223602485, 'fraction_numerical': 0.011227902532250358, 'mean_word_length': 5.667197452229299, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 5, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '503226', 'license': 'MIT', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1277, 'n_words': 474, 'path': 'exercise-2/exercise.ipynb', 'repo_name': 'mportwood/ch12-apis', 'size': '4204'}