1) What books topped the Hardcover Fiction NYT best-sellers list on Mother's Day in 2009 and 2010? How about Father's Day?


In [42]:
import requests

In [61]:
# mother's day in 2010
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?bestsellers-date=2010-05-04&rank=20&api-key=a6019bd075824e40941fd84de1e3de28")
data = response.json()

In [62]:
type(data)


Out[62]:
dict

In [63]:
data.keys()


Out[63]:
dict_keys(['num_results', 'results', 'status', 'copyright', 'last_modified'])

In [64]:
type(data['results'])


Out[64]:
list

In [65]:
data['results'][0]['book_details'][0]['title']


Out[65]:
"THE EMPEROR'S REVENGE"

In [56]:
# mother's day in 2010
for result in data['results']:
    for title in result['book_details']:
        print (title['title'])


THE EMPEROR'S REVENGE
BEFORE THE FALL
ALL SUMMER LONG
THE GIRL ON THE TRAIN
AFTER YOU
15TH AFFAIR
A HERO OF FRANCE
THE WEEKENDERS
THE LAST MILE
THE NEST
THE CITY OF MIRRORS
ALL THE LIGHT WE CANNOT SEE
THE NIGHTINGALE
MODERN LOVERS
EXTREME PREY
SWEETBITTER
THE ISLAND HOUSE
THE APARTMENT
THE FIREMAN
EVERYBODY'S FOOL

In [66]:
# mother's day in 2009
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?bestsellers-date=2009-05-04&rank=20&api-key=a6019bd075824e40941fd84de1e3de28")
data = response.json()

In [67]:
# mother's day in 2009
for result in data['results']:
    for title in result['book_details']:
        print (title['title'])


THE EMPEROR'S REVENGE
BEFORE THE FALL
ALL SUMMER LONG
THE GIRL ON THE TRAIN
AFTER YOU
15TH AFFAIR
A HERO OF FRANCE
THE WEEKENDERS
THE LAST MILE
THE NEST
THE CITY OF MIRRORS
ALL THE LIGHT WE CANNOT SEE
THE NIGHTINGALE
MODERN LOVERS
EXTREME PREY
SWEETBITTER
THE ISLAND HOUSE
THE APARTMENT
THE FIREMAN
EVERYBODY'S FOOL

2) What are all the different book categories the NYT ranked in June 6, 2009? How about June 6, 2015?


In [85]:
# June 6, 2009
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/names.json?bestsellers-date=2009-06-06&api-key=a6019bd075824e40941fd84de1e3de28")
data = response.json()

In [86]:
data.keys()


Out[86]:
dict_keys(['num_results', 'results', 'status', 'copyright'])

In [89]:
data['results'][0]['list_name']


Out[89]:
'Combined Print and E-Book Fiction'

In [90]:
# June 6, 2009
for categories in data['results']:
    print (categories['list_name'])


Combined Print and E-Book Fiction
Combined Print and E-Book Nonfiction
Hardcover Fiction
Hardcover Nonfiction
Trade Fiction Paperback
Mass Market Paperback
Paperback Nonfiction
E-Book Fiction
E-Book Nonfiction
Hardcover Advice
Paperback Advice
Advice How-To and Miscellaneous
Chapter Books
Childrens Middle Grade
Childrens Middle Grade E-Book
Childrens Middle Grade Hardcover
Childrens Middle Grade Paperback
Paperback Books
Picture Books
Series Books
Young Adult
Young Adult E-Book
Young Adult Hardcover
Young Adult Paperback
Hardcover Graphic Books
Paperback Graphic Books
Manga
Combined Print Fiction
Combined Print Nonfiction
Animals
Business Books
Celebrities
Crime and Punishment
Culture
Education
Espionage
Expeditions Disasters and Adventures
Fashion Manners and Customs
Food and Fitness
Games and Activities
Hardcover Business Books
Health
Humor
Indigenous Americans
Relationships
Paperback Business Books
Family
Hardcover Political Books
Race and Civil Rights
Religion Spirituality and Faith
Science
Sports
Travel

In [91]:
# June 6, 2015
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/names.json?bestsellers-date=2015-06-06&api-key=a6019bd075824e40941fd84de1e3de28")
data = response.json()

In [92]:
# June 6, 2015
for categories in data['results']:
    print (categories['list_name'])


Combined Print and E-Book Fiction
Combined Print and E-Book Nonfiction
Hardcover Fiction
Hardcover Nonfiction
Trade Fiction Paperback
Mass Market Paperback
Paperback Nonfiction
E-Book Fiction
E-Book Nonfiction
Hardcover Advice
Paperback Advice
Advice How-To and Miscellaneous
Chapter Books
Childrens Middle Grade
Childrens Middle Grade E-Book
Childrens Middle Grade Hardcover
Childrens Middle Grade Paperback
Paperback Books
Picture Books
Series Books
Young Adult
Young Adult E-Book
Young Adult Hardcover
Young Adult Paperback
Hardcover Graphic Books
Paperback Graphic Books
Manga
Combined Print Fiction
Combined Print Nonfiction
Animals
Business Books
Celebrities
Crime and Punishment
Culture
Education
Espionage
Expeditions Disasters and Adventures
Fashion Manners and Customs
Food and Fitness
Games and Activities
Hardcover Business Books
Health
Humor
Indigenous Americans
Relationships
Paperback Business Books
Family
Hardcover Political Books
Race and Civil Rights
Religion Spirituality and Faith
Science
Sports
Travel

In [ ]: