Assignment 6

Quarto

Assignment 6

The OMDB API

1: The OMDB API is a website with all sorts of information related to Movies. This Includes all information about the movie including: Title, Year, Rating, Actors, Box Office Revenue, and IMDB rating. This can be used to help determine what movie to watch. This is done by pulling relevant information on a movie you suggest to the API.

Loading In Library’s

library(tidyverse) # All the tidy things
library(jsonlite)  # Converting json data into data frames
library(magrittr)  # Extracting items from list objects using piping grammar
library(httr)      # Interacting with HTTP verbs
library(readr)

Setting Up the API

1) Get a free API at https://www.omdbapi.com/apikey.aspx

2) You can also get the base URL from the website. For student and research purposes, you are allowed to look at data regarding movies. After inputting your API Key and Movie Title you are good to go when making your URL.

key <- "&apikey=<YOUR API KEY>"
movie <- "<ENTER YOUR MOVIE >"
base_url <- "https://www.omdbapi.com/?t="

url <- paste0(base_url, movie, key, sep = "")

Pulling the Data

After you have built the URL the next step is pulling the data and turning into a text. This will simplify our data table later and ensure it is nice and easy to read.

test_Movie <- 
  url %>%
  GET() %>%
  content(as = "text", 
          encoding = "UTF-8") %>%
  fromJSON()

Making the Data Frame

The next thing you have to do is make the data frame. As I’ve done so below this allows you to parse out the data you might not want such as a link to the poster, writers, and other information that might not be relevant to picking which movie you are going to watch. This can be done below by on the left naming the column and then telling the API where to call the information from.

Movie_DT <- data.frame(imdbRating = test_Movie$imdbRating,

Title = test_Movie$Title,

Year = test_Movie$Year,

Rating = test_Movie$Rated,

Genre = test_Movie$Genre,

Revenue = test_Movie$BoxOffice

)

Movie_DT <- data.frame(imdbRating = test_Movie$imdbRating,
                       Title = test_Movie$Title,
                       Year = test_Movie$Year,
                       Rating = test_Movie$Rated,
                       Genre = test_Movie$Genre,
                       Revenue = test_Movie$BoxOffice
                       )

Result

Finally, you use that data table and organize the columns into a clean format that makes sense.

Movie_DT %>% 
  select(Title, Year, imdbRating, Rating, Genre, Revenue)
  Title Year imdbRating Rating                        Genre      Revenue
1  Cars 2006        7.3      G Animation, Adventure, Comedy $244,082,982