library(tidytext)
library(httr)
library(RCurl)
library(jsonlite)
Select one of the New York Times API’s, construct an interface in R to read in the JSON data, and transform it into an R Dataframe.
Question: What are the NY Times bestsellers in hard-cover fiction currently, 5 years ago and 10 years ago based on the information in the created data frames.
https://api.nytimes.com/svc/books/v3/lists/{YYYY-MM-DD}/{list}.json
#Conclusions
A lot more could be done with the available API data with more time and work. Evaluation of how long a book stays on list, how it changes position in the rankings and any trends for common authors sitting on the best seller list. Interesting was seeing Nicholas Sparks show up twice but 5 yrs apart on the best sellar lists.
library(httr)
#NYTIMES_KEY="NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS"
url <- "https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS"
(nybook <- GET(url))
## Response [https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS]
## Date: 2021-10-25 00:34
## Status: 200
## Content-Type: application/json; charset=UTF-8
## Size: 34.9 kB
urlhistory<- "https://api.nytimes.com/svc/books/v3/lists/2016-10-20/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS"
(nybookhistory5<- GET(urlhistory))
## Response [https://api.nytimes.com/svc/books/v3/lists/2016-10-20/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS]
## Date: 2021-10-25 00:34
## Status: 200
## Content-Type: application/json; charset=UTF-8
## Size: 48.6 kB
urlhistoryten<- "https://api.nytimes.com/svc/books/v3/lists/2011-10-25/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS"
(nybookhistory10<- GET(urlhistoryten))
## Response [https://api.nytimes.com/svc/books/v3/lists/2011-10-25/hardcover-fiction.json?api-key=NR8j0hBE2jWMktrnSnhdBl83TI3cw8lS]
## Date: 2021-10-25 00:34
## Status: 200
## Content-Type: application/json; charset=UTF-8
## Size: 49.3 kB
dfbookscurrent<-fromJSON(url)
#current best sellers hardcover fiction
dfbooks5yrago <-fromJSON(urlhistory)
# best sellers hardcover fiction 5 yr ago
dfbooks10yrago<-fromJSON(urlhistoryten)
# best seller hardcover fiction 10 yr ago
###We can find the best sellers as a list or identify it by looking at the list to find the #1 best seller.
#1 Best Seller Author Weeks on List
Current Oct 2021 State of Terror Hillary Clinton & Louise Penny 1 5 yr ago Oct 2016 Two by Two Nicholas Sparks 1 10 yr ago Oct 2011 The best of me Nicholas Sparks 1
A lot more could be done with the available API data with more time and work. Evaluation of how long a book stays on list, how it changes position in the rankings and any trends for common authors sitting on the best seller list. Interesting was seeing Nicholas Sparks show up twice but 5 yrs apart on the best sellar lists.
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: so embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.