I choose The BOOK API from The New York Times web site: http://developer.nytimes.com/docs. I obtained (by registering) an API key from the web site. Then I used the instruction found in Books API: Best Sellers Link: http://developer.nytimes.com/docs/books_api/Books_API_Best_Sellers to read the file into R and create a dataframe.
jsonlite package to obtain the list names.httr package to create the same dataframe.Using the jsonlite package I read the JSON file that contains the list name (the name of the Times best-seller list). I did this step so that I can see the complete list of names found in the Book API.
library(jsonlite)
res <- fromJSON("http://api.nytimes.com/svc/books/v3/lists/names?api-key=0ebfcb34c7334257471f7024c5ca0d48:8:73344009")
colnames(res$results)
## [1] "list_name" "display_name" "list_name_encoded"
## [4] "oldest_published_date" "newest_published_date" "updated"
list_name <- res$results$list_name
list_name
## [1] "Combined Print and E-Book Fiction"
## [2] "Combined Print and E-Book Nonfiction"
## [3] "Hardcover Fiction"
## [4] "Hardcover Nonfiction"
## [5] "Trade Fiction Paperback"
## [6] "Mass Market Paperback"
## [7] "Paperback Nonfiction"
## [8] "E-Book Fiction"
## [9] "E-Book Nonfiction"
## [10] "Hardcover Advice"
## [11] "Paperback Advice"
## [12] "Advice How-To and Miscellaneous"
## [13] "Picture Books"
## [14] "Chapter Books"
## [15] "Childrens Middle Grade"
## [16] "Young Adult"
## [17] "Paperback Books"
## [18] "Childrens Middle Grade Hardcover"
## [19] "Childrens Middle Grade Paperback"
## [20] "Childrens Middle Grade E-Book"
## [21] "Young Adult Hardcover"
## [22] "Young Adult Paperback"
## [23] "Young Adult E-Book"
## [24] "Series Books"
## [25] "Hardcover Graphic Books"
## [26] "Paperback Graphic Books"
## [27] "Manga"
## [28] "Combined Print Fiction"
## [29] "Combined Print Nonfiction"
## [30] "Animals"
## [31] "Business Books"
## [32] "Celebrities"
## [33] "Crime and Punishment"
## [34] "Culture"
## [35] "Education"
## [36] "Espionage"
## [37] "Expeditions Disasters and Adventures"
## [38] "Family"
## [39] "Fashion Manners and Customs"
## [40] "Food and Fitness"
## [41] "Games and Activities"
## [42] "Hardcover Business Books"
## [43] "Health"
## [44] "Humor"
## [45] "Indigenous Americans"
## [46] "Paperback Business Books"
## [47] "Hardcover Political Books"
## [48] "Race and Civil Rights"
## [49] "Relationships"
## [50] "Religion Spirituality and Faith"
## [51] "Science"
## [52] "Sports"
## [53] "Travel"
jsonlite I obtained the JSON API that contains the information about e-book fiction. With that information I created a datafrme with a subset of the original data (choose only the columns that I wanted).res2 <- fromJSON("http://api.nytimes.com/svc/books/v3/lists/E-Book-Fiction?api-key=0ebfcb34c7334257471f7024c5ca0d48:8:73344009")
books_t0 <- data.frame(res2$results$books)
head(books_t0,3)
## rank rank_last_week weeks_on_list asterisk dagger primary_isbn10
## 1 1 0 1 0 0 0385539444
## 2 2 0 1 0 0 0316349925
## 3 3 0 2 0 0 1455520594
## primary_isbn13 publisher
## 1 9780385539449 Doubleday
## 2 9780316349925 Mulholland/Little, Brown
## 3 9781455520596 Grand Central
## description
## 1 The attorney Sebastian Rudd is a <U+0093>lone gunman<U+0094> who hates injustice and the system and defends unpopular clients.
## 2 In the third novel about the private investigative team of Cormoran Strike and Robin Ellacott, the pair pursue a psychotic stalker; by J.<U+2009>K. Rowling, writing pseudonymously.
## 3 A couple in love are threatened by secrets from the past.
## price title author contributor
## 1 0 ROGUE LAWYER John Grisham by John Grisham
## 2 0 CAREER OF EVIL Robert Galbraith by Robert Galbraith
## 3 0 SEE ME Nicholas Sparks by Nicholas Sparks
## contributor_note book_image amazon_product_url age_group
## 1 <NA> <NA>
## 2 <NA> <NA>
## 3 <NA> <NA>
## book_review_link first_chapter_link sunday_review_link
## 1
## 2
## 3
## article_chapter_link
## 1
## 2
## 3
## isbns
## 1 0385539436, 0385539444, 9780385539432, 9780385539449
## 2 0316349933, 0316352454, 0316349925, 9780316349932, 9780316352451, 9780316349925
## 3 1455520616, 1455530069, 1455520594, 9781455520619, 9781455530069, 9781455520596
books_t1 <- data.frame(books_t0[c(1, 3, 11:13, 6:8)])
head(books_t1)
## rank weeks_on_list title author
## 1 1 1 ROGUE LAWYER John Grisham
## 2 2 1 CAREER OF EVIL Robert Galbraith
## 3 3 2 SEE ME Nicholas Sparks
## 4 4 19 THE MARTIAN Andy Weir
## 5 5 1 KIAN Tijan
## 6 6 3 THE SURVIVOR Vince Flynn and Kyle Mills
## contributor primary_isbn10 primary_isbn13
## 1 by John Grisham 0385539444 9780385539449
## 2 by Robert Galbraith 0316349925 9780316349925
## 3 by Nicholas Sparks 1455520594 9781455520596
## 4 by Andy Weir None 9780804139038
## 5 by Tijan None A00B016TO0AOG
## 6 by Vince Flynn and Kyle Mills 1476783470 9781476783475
## publisher
## 1 Doubleday
## 2 Mulholland/Little, Brown
## 3 Grand Central
## 4 Crown
## 5 Tijan
## 6 Emily Bestler/Atria
httr package, to obtain the Books API from online, as was shown in the textbook (for this class). Therefore, I used the httr package to obtain the Book API and used the package jsonlite to read the file and create a database. It look the same as only using the jsonlite package.library(httr)
link <- GET("http://api.nytimes.com/svc/books/v3/lists/E-Book-Fiction?api-key=0ebfcb34c7334257471f7024c5ca0d48:8:73344009", content_type_json())
#Using 'jsonlite' package:
jsonfile <- content(link, as = "text")
res <- fromJSON(jsonfile)
books_t2 <- data.frame(res$results$books)
books_t3 <- data.frame(books_t2[c(1, 3, 11:13, 6:8)])
head(books_t3)
## rank weeks_on_list title author
## 1 1 1 ROGUE LAWYER John Grisham
## 2 2 1 CAREER OF EVIL Robert Galbraith
## 3 3 2 SEE ME Nicholas Sparks
## 4 4 19 THE MARTIAN Andy Weir
## 5 5 1 KIAN Tijan
## 6 6 3 THE SURVIVOR Vince Flynn and Kyle Mills
## contributor primary_isbn10 primary_isbn13
## 1 by John Grisham 0385539444 9780385539449
## 2 by Robert Galbraith 0316349925 9780316349925
## 3 by Nicholas Sparks 1455520594 9781455520596
## 4 by Andy Weir None 9780804139038
## 5 by Tijan None A00B016TO0AOG
## 6 by Vince Flynn and Kyle Mills 1476783470 9781476783475
## publisher
## 1 Doubleday
## 2 Mulholland/Little, Brown
## 3 Grand Central
## 4 Crown
## 5 Tijan
## 6 Emily Bestler/Atria
knitr package.write.csv(books_t1, file = "C:/Users/Nabila/Documents/GitHub/Class-IS607/Week 10 Assignment/books.csv")
library(knitr)
kable(books_t1, caption = "Table of the Top 15 New York Times Best Selling e-book fiction.", align = "c")
| rank | weeks_on_list | title | author | contributor | primary_isbn10 | primary_isbn13 | publisher |
|---|---|---|---|---|---|---|---|
| 1 | 1 | ROGUE LAWYER | John Grisham | by John Grisham | 0385539444 | 9780385539449 | Doubleday |
| 2 | 1 | CAREER OF EVIL | Robert Galbraith | by Robert Galbraith | 0316349925 | 9780316349925 | Mulholland/Little, Brown |
| 3 | 2 | SEE ME | Nicholas Sparks | by Nicholas Sparks | 1455520594 | 9781455520596 | Grand Central |
| 4 | 19 | THE MARTIAN | Andy Weir | by Andy Weir | None | 9780804139038 | Crown |
| 5 | 1 | KIAN | Tijan | by Tijan | None | A00B016TO0AOG | Tijan |
| 6 | 3 | THE SURVIVOR | Vince Flynn and Kyle Mills | by Vince Flynn and Kyle Mills | 1476783470 | 9781476783475 | Emily Bestler/Atria |
| 7 | 1 | THE LAKE HOUSE | Kate Morton | by Kate Morton | 1451649371 | 9781451649376 | Atria |
| 8 | 4 | THE MURDER HOUSE | James Patterson and David Ellis | by James Patterson and David Ellis | 0316337978 | 9780316337977 | Little, Brown |
| 9 | 2 | WRONG | Jana Aston | by Jana Aston | 069252777X | 9780692527771 | Rutherford |
| 10 | 4 | PRETTY GIRLS | Karin Slaughter | by Karin Slaughter | 006242906X | 9780062429063 | Morrow/HarperCollins |
| 11 | 0 | PIRATE LATITUDES | Michael Crichton | by Michael Crichton | 0061938742 | 9780061938740 | Harper |
| 12 | 0 | FEAR THE DARK | Kay Hooper | by Kay Hooper | None | 9780698191938 | Berkley |
| 13 | 0 | YOU’LL BE MINE | Marie Force | by Marie Force | None | 9781101988787 | InterMix |
| 14 | 0 | THE GIRL IN THE SPIDER’S WEB | David Lagercrantz | by David Lagercrantz | 0385354290 | 9780385354295 | Knopf |
| 15 | 0 | THE GIRL ON THE TRAIN | Paula Hawkins | by Paula Hawkins | 0698185390 | 9780698185395 | Riverhead |