I googled ‘http://www.storybench.org/working-with-the-new-york-times-api-in-r/’
#install.packages("devtools")
#devtools::install_github("mkearney/nytimes")
#install.packages("jsonlite")
library(jsonlite)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
The usefulness of this API request would be in figuring out the longest running current books on the Best Seller list
As of this submission, HOLY GHOST by John Sandford has been on the best seller list longest.
Of course, I can also do a historical rank for the future.
Lastly, I should probably add a regex to remove or trim off the timestamp from the yyy-mm-dd hh-mm-ss
LISTOVERVIEW <- toString(paste("https://api.nytimes.com/svc/books/v3/lists/overview/2018-11-02.json?api-key=", NYTIMES_KEY, sep=""))
y <- fromJSON(LISTOVERVIEW, flatten = TRUE) %>% data.frame()
z <- (y$results.lists.books[1])
names(z) <- c("top_book_list")
cat("Top Books on the Best Seller List, and how many times it has appeared on the list:")
## Top Books on the Best Seller List, and how many times it has appeared on the list:
for(i in 1:length(z$top_book_list$author)){
cat("\n", z$top_book_list$title[i], "by: ", z$top_book_list$author[i], " has been on the best seller list for", z$top_book_list$weeks_on_list[i], "weeks", "as of", z$top_book_list$created_date[i])
}
##
## EVERY BREATH by: Nicholas Sparks has been on the best seller list for 1 weeks as of 2018-10-24 22:02:10
## UNSHELTERED by: Barbara Kingsolver has been on the best seller list for 1 weeks as of 2018-10-24 22:02:10
## HOLY GHOST by: John Sandford has been on the best seller list for 2 weeks as of 2018-10-24 22:02:10
## THE NEXT PERSON YOU MEET IN HEAVEN by: Mitch Albom has been on the best seller list for 2 weeks as of 2018-10-24 22:02:10
## DESPERATE MEASURES by: Stuart Woods has been on the best seller list for 1 weeks as of 2018-10-24 22:02:10
Sources Cited: http://www.storybench.org/working-with-the-new-york-times-api-in-r/ https://github.com/NYTimes/public_api_specs/blob/master/books_api/books_api.md