Week9 Assignment (Web APIs)
(2) Get all the books available. Read the JSON data into R data frame.
url1 = "http://api.nytimes.com/svc/books/v3/lists/names.json?"
key1 = "api-key=c991ccaa513642319cd329b0edde7749"
fullUrl1 = paste0(url1, key1)
booksInfo_data = fromJSON(fullUrl1)
booksInfo_df = data.frame(booksInfo_data$results)
colnames(booksInfo_df) = c("List Name", "Display Name", "Encoded List Name", "Published Date (Oldest)", "Published Date (Newest)", "Updated")
class(booksInfo_df)
## [1] "data.frame"
head(booksInfo_df, 10)
## List Name Display Name Encoded List Name Published Date (Oldest) Published Date (Newest) Updated
## 1 Combined Print and E-Book Fiction Combined Print & E-Book Fiction combined-print-and-e-book-fiction 2011-02-13 2016-11-06 WEEKLY
## 2 Combined Print and E-Book Nonfiction Combined Print & E-Book Nonfiction combined-print-and-e-book-nonfiction 2011-02-13 2016-11-06 WEEKLY
## 3 Hardcover Fiction Hardcover Fiction hardcover-fiction 2008-06-08 2016-11-06 WEEKLY
## 4 Hardcover Nonfiction Hardcover Nonfiction hardcover-nonfiction 2008-06-08 2016-11-06 WEEKLY
## 5 Trade Fiction Paperback Paperback Trade Fiction trade-fiction-paperback 2008-06-08 2016-11-06 WEEKLY
## 6 Mass Market Paperback Paperback Mass-Market Fiction mass-market-paperback 2008-06-08 2016-11-06 WEEKLY
## 7 Paperback Nonfiction Paperback Nonfiction paperback-nonfiction 2008-06-08 2016-11-06 WEEKLY
## 8 E-Book Fiction E-Book Fiction e-book-fiction 2011-02-13 2016-11-06 WEEKLY
## 9 E-Book Nonfiction E-Book Nonfiction e-book-nonfiction 2011-02-13 2016-11-06 WEEKLY
## 10 Hardcover Advice Hardcover Advice & Misc. hardcover-advice 2008-06-08 2013-04-21 WEEKLY
nrow(booksInfo_df)
## [1] 53
(3) Get all Health related books. Read the JSON data into R data frame.
url2 = "http://api.nytimes.com/svc/books/v3/lists/health.json?"
key2 = "api-key=c991ccaa513642319cd329b0edde7749"
fullUrl2 = paste0(url2, key2)
books_data = fromJSON(fullUrl2)
books_df = data.frame(books_data$results$books)
class(books_df)
## [1] "data.frame"
head(books_df, 2)
## rank rank_last_week weeks_on_list asterisk dagger primary_isbn10 primary_isbn13 publisher description price title author contributor contributor_note book_image book_image_width book_image_height amazon_product_url age_group book_review_link first_chapter_link sunday_review_link article_chapter_link isbns buy_links
## 1 1 0 0 0 0 081298840X 9780812988406 Random House A memoir by a physician who received a diagnosis of Stage IV lung cancer at the age of 36. 0 WHEN BREATH BECOMES AIR Paul Kalanithi by Paul Kalanithi https://s1.nyt.com/du/books/images/9780812988413.jpg 338 500 http://www.amazon.com/When-Breath-Becomes-Paul-Kalanithi-ebook/dp/B00XSSYR50?tag=thenewyorktim-20 081298840X, 0812988418, 1410487857, 9780812988406, 9780812988413, 9781410487858 Local Booksellers, Barnes and Noble, Amazon, http://www.indiebound.org/book/9780812988406?aff=NYT, http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9780812988406, http://www.amazon.com/When-Breath-Becomes-Paul-Kalanithi-ebook/dp/B00XSSYR50?tag=thenewyorktim-20
## 2 2 0 0 0 0 1455559636 9781455559633 Grand Central The co-anchor of World News Tonight and 20/20 describes her long struggle with acute anxiety and panic attacks, which she attempted to medicate with alcohol. 0 BETWEEN BREATHS Elizabeth Vargas by Elizabeth Vargas https://s1.nyt.com/du/books/images/9781455559640.jpg 334 500 http://www.amazon.com/Between-Breaths-Memoir-Panic-Addiction-ebook/dp/B0169ATL3Q?tag=thenewyorktim-20 1455559636, 1455559644, 1455566039, 9781455559633, 9781455559640, 9781455566037 Local Booksellers, Barnes and Noble, Amazon, http://www.indiebound.org/book/9781455559633?aff=NYT, http://www.anrdoezrs.net/click-7990613-11819508?url=http%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781455559633, http://www.amazon.com/Between-Breaths-Memoir-Panic-Addiction-ebook/dp/B0169ATL3Q?tag=thenewyorktim-20
books_df = select(books_df, matches("primary_isbn13|publisher|title|author"))
colnames(books_df) = c("ISBN-13", "Publisher", "Title", "Author")
books_df = books_df[c("Title", "Author", "Publisher", "ISBN-13")]
print(books_df)
## Title Author Publisher ISBN-13
## 1 WHEN BREATH BECOMES AIR Paul Kalanithi Random House 9780812988406
## 2 BETWEEN BREATHS Elizabeth Vargas Grand Central 9781455559633
## 3 THE SUBTLE ART OF NOT GIVING A -------- Mark Manson HarperOne/HarperCollins 9780062457714
## 4 BEING MORTAL Atul Gawande Metropolitan/Holt 9780805095159
## 5 EAT FAT, GET THIN Mark Hyman Little, Brown 9780316338837
## 6 10-DAY GREEN SMOOTHIE CLEANSE J J Smith Atria 9781501100109
## 7 HOW NOT TO DIE Michael Greger with Gene Stone Flatiron 9781250066114
## 8 THE FAST METABOLISM DIET Haylie Pomroy with Eve Adamson Harmony 9780307986276
## 9 MEDICAL MEDIUM Anthony William Hay House 9781401948290
## 10 INNER ENGINEERING Sadhguru Spiegel & Grau 9780812997798