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


In [1]:
#my IPA key b577eb5b46ad4bec8ee159c89208e220
#base url http://api.nytimes.com/svc/books/{version}/lists

graded = 8/8


In [2]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists.json?list=hardcover-fiction&published-date=2009-05-10&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller = response.json()
print(best_seller.keys())


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

In [3]:
print(type(best_seller))


<class 'dict'>

In [4]:
print(type(best_seller['results']))


<class 'list'>

In [5]:
print(len(best_seller['results']))


20

In [6]:
print(best_seller['results'][0])


{'book_details': [{'contributor_note': '', 'price': 27.99, 'description': 'Former Secret Service agents, now P.I.’s, search for a child abducted from a party at Camp David.', 'age_group': '', 'contributor': 'by David Baldacci', 'author': 'David Baldacci', 'primary_isbn10': '044654695X', 'title': 'FIRST FAMILY', 'primary_isbn13': '9780446546959', 'publisher': 'Grand Central'}], 'rank': 1, 'rank_last_week': 0, 'published_date': '2009-05-10', 'dagger': 0, 'asterisk': 0, 'weeks_on_list': 1, 'reviews': [{'article_chapter_link': '', 'first_chapter_link': '', 'book_review_link': '', 'sunday_review_link': ''}], 'bestsellers_date': '2009-04-25', 'list_name': 'Hardcover Fiction', 'display_name': 'Hardcover Fiction', 'amazon_product_url': 'http://www.amazon.com/First-Family-Maxwell-David-Baldacci/dp/0446539740?tag=thenewyorktim-20', 'isbns': [{'isbn13': '9780446539746', 'isbn10': '0446539740'}]}

In [7]:
mother_best_seller_results_2009 = best_seller['results']

for item in mother_best_seller_results_2009:
    print("This books ranks #", item['rank'], "on the list") #just to make sure they are in order
    for book in item['book_details']:
        print(book['title'])


This books ranks # 1 on the list
FIRST FAMILY
This books ranks # 2 on the list
TEA TIME FOR THE TRADITIONALLY BUILT
This books ranks # 3 on the list
LOITERING WITH INTENT
This books ranks # 4 on the list
JUST TAKE MY HEART
This books ranks # 5 on the list
THE PERFECT POISON
This books ranks # 6 on the list
THE HOST
This books ranks # 7 on the list
LOOK AGAIN
This books ranks # 8 on the list
DEADLOCK
This books ranks # 9 on the list
LONG LOST
This books ranks # 10 on the list
TURN COAT
This books ranks # 11 on the list
THE ASSOCIATE
This books ranks # 12 on the list
HANDLE WITH CARE
This books ranks # 13 on the list
THE HELP
This books ranks # 14 on the list
THE GUERNSEY LITERARY AND POTATO PEEL PIE SOCIETY
This books ranks # 15 on the list
FATALLY FLAKY
This books ranks # 16 on the list
ARTHAS
This books ranks # 17 on the list
A RELIABLE WIFE
This books ranks # 18 on the list
BORDERLINE
This books ranks # 19 on the list
ONE SECOND AFTER
This books ranks # 20 on the list
BONEMAN'S DAUGHTERS

In [8]:
print("The top 3 books in the Hardcover fiction NYT best-sellers on Mother's day 2009 were:")
for item in mother_best_seller_results_2009:
    if item['rank']< 4: #to get top 3 books on the list
        for book in item['book_details']:
            print(book['title'])


The top 3 books in the Hardcover fiction NYT best-sellers on Mother's day 2009 were:
FIRST FAMILY
TEA TIME FOR THE TRADITIONALLY BUILT
LOITERING WITH INTENT

In [9]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists.json?list=hardcover-fiction&published-date=2010-05-09&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller_2010 = response.json()
print(best_seller.keys())


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

In [10]:
print(best_seller_2010['results'][0])


{'book_details': [{'contributor_note': '', 'price': 27.99, 'description': 'Two agents are tracking the same man, a human trafficker who is now dealing in nuclear arms.', 'age_group': '', 'contributor': 'by David Baldacci', 'author': 'David Baldacci', 'primary_isbn10': '0446564087', 'title': 'DELIVER US FROM EVIL', 'primary_isbn13': '9780446564083', 'publisher': 'Grand Central'}], 'rank': 1, 'rank_last_week': 0, 'published_date': '2010-05-09', 'dagger': 0, 'asterisk': 0, 'weeks_on_list': 1, 'reviews': [{'article_chapter_link': '', 'first_chapter_link': '', 'book_review_link': '', 'sunday_review_link': ''}], 'bestsellers_date': '2010-04-25', 'list_name': 'Hardcover Fiction', 'display_name': 'Hardcover Fiction', 'amazon_product_url': 'http://www.amazon.com/Deliver-Us-Evil-David-Baldacci/dp/0446564079?tag=thenewyorktim-20', 'isbns': [{'isbn13': '9780446564076', 'isbn10': '0446564079'}, {'isbn13': '9780446576253', 'isbn10': '0446576255'}, {'isbn13': '9780892962617', 'isbn10': '0892962615'}, {'isbn13': '9780446564083', 'isbn10': '0446564087'}]}

In [11]:
mother_best_seller_2010_results = best_seller_2010['results']

In [12]:
print("The top 3 books in the Hardcover fiction NYT best-sellers on Mother's day 2010 were:")
for item in mother_best_seller_2010_results:
    if item['rank']< 4: #to get top 3 books on the list
        for book in item['book_details']:
            print(book['title'])


The top 3 books in the Hardcover fiction NYT best-sellers on Mother's day 2010 were:
DELIVER US FROM EVIL
THE HELP
THE DOUBLE COMFORT SAFARI CLUB

In [13]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists.json?list=hardcover-fiction&published-date=2009-06-21&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller = response.json()

In [14]:
father_best_seller_results_2009 = best_seller['results']
print("The top 3 books in the Hardcover fiction NYT best-sellers on Father's day 2009 were:")
for item in father_best_seller_results_2009:
    if item['rank']< 4: #to get top 3 books on the list
        for book in item['book_details']:
            print(book['title'])


The top 3 books in the Hardcover fiction NYT best-sellers on Father's day 2009 were:
SKIN TRADE
MEDUSA
THE SCARECROW

In [15]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists.json?list=hardcover-fiction&published-date=2010-06-20&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller = response.json()

In [16]:
father_best_seller_results_2010 = best_seller['results']
print("The top 3 books in the Hardcover fiction NYT best-sellers on Father's day 2010 were:")
for item in father_best_seller_results_2010:
    if item['rank']< 4: #to get top 3 books on the list
        for book in item['book_details']:
            print(book['title'])


The top 3 books in the Hardcover fiction NYT best-sellers on Father's day 2010 were:
THE GIRL WHO KICKED THE HORNET’S NEST
BULLET
THE SPY

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


In [17]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/names.json?published-date=2009-06-06&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller = response.json()

In [18]:
print(best_seller.keys())


dict_keys(['copyright', 'num_results', 'results', 'status'])

In [19]:
print(len(best_seller['results']))


53

In [20]:
book_categories_2009 = best_seller['results']

In [21]:
for item in book_categories_2009:
    print(item['display_name'])


Combined Print & E-Book Fiction
Combined Print & E-Book Nonfiction
Hardcover Fiction
Hardcover Nonfiction
Paperback Trade Fiction
Paperback Mass-Market Fiction
Paperback Nonfiction
E-Book Fiction
E-Book Nonfiction
Hardcover Advice & Misc.
Paperback Advice & Misc.
Advice, How-To & Miscellaneous
Children’s Chapter Books
Children’s Middle Grade
Children’s Middle Grade E-Book
Children’s Middle Grade Hardcover
Children’s Middle Grade Paperback
Children’s Paperback Books
Children’s Picture Books
Children’s Series
Young Adult
Young Adult E-Book
Young Adult Hardcover
Young Adult Paperback
Hardcover Graphic Books
Paperback Graphic Books
Manga
Combined Hardcover & Paperback Fiction
Combined Hardcover & Paperback Nonfiction
Animals
Business
Celebrities
Crime and Punishment
Culture
Education
Espionage
Expeditions
Fashion, Manners and Customs
Food and Diet
Games and Activities
Hardcover Business Books
Health
Humor
Indigenous Americans
Love and Relationships
Paperback Business Books
Parenthood and Family
Politics and American History
Race and Civil Rights
Religion, Spirituality and Faith
Science
Sports and Fitness
Travel

In [22]:
import requests
response = requests.get("http://api.nytimes.com/svc/books/v2/lists/names.json?published-date=2015-06-06&api-key=b577eb5b46ad4bec8ee159c89208e220")
best_seller = response.json()

print(len(best_seller['results']))


53

In [23]:
book_categories_2015 = best_seller['results']
for item in book_categories_2015:
    print(item['display_name'])


Combined Print & E-Book Fiction
Combined Print & E-Book Nonfiction
Hardcover Fiction
Hardcover Nonfiction
Paperback Trade Fiction
Paperback Mass-Market Fiction
Paperback Nonfiction
E-Book Fiction
E-Book Nonfiction
Hardcover Advice & Misc.
Paperback Advice & Misc.
Advice, How-To & Miscellaneous
Children’s Chapter Books
Children’s Middle Grade
Children’s Middle Grade E-Book
Children’s Middle Grade Hardcover
Children’s Middle Grade Paperback
Children’s Paperback Books
Children’s Picture Books
Children’s Series
Young Adult
Young Adult E-Book
Young Adult Hardcover
Young Adult Paperback
Hardcover Graphic Books
Paperback Graphic Books
Manga
Combined Hardcover & Paperback Fiction
Combined Hardcover & Paperback Nonfiction
Animals
Business
Celebrities
Crime and Punishment
Culture
Education
Espionage
Expeditions
Fashion, Manners and Customs
Food and Diet
Games and Activities
Hardcover Business Books
Health
Humor
Indigenous Americans
Love and Relationships
Paperback Business Books
Parenthood and Family
Politics and American History
Race and Civil Rights
Religion, Spirituality and Faith
Science
Sports and Fitness
Travel

3) Muammar Gaddafi's name can be transliterated many many ways. His last name is often a source of a million and one versions - Gadafi, Gaddafi, Kadafi, and Qaddafi to name a few. How many times has the New York Times referred to him by each of those names?

Tip: Add "Libya" to your search to make sure (-ish) you're talking about the right guy.


In [24]:
import requests
response = requests.get("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Gadafi&fq=Libya&api-key=b577eb5b46ad4bec8ee159c89208e220")
gadafi = response.json()

print(gadafi.keys())
print(gadafi['response'])
print(gadafi['response'].keys())
print(gadafi['response']['docs']) #so no results for GADAFI.


dict_keys(['copyright', 'response', 'status'])
{'docs': [], 'meta': {'offset': 0, 'time': 30, 'hits': 0}}
dict_keys(['docs', 'meta'])
[]

In [25]:
print('The New York times has not used the name Gadafi to refer to Muammar Gaddafi')


The New York times has not used the name Gadafi to refer to Muammar Gaddafi

In [26]:
import requests
response = requests.get("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Gaddafi&fq=Libya&api-key=b577eb5b46ad4bec8ee159c89208e220")
gaddafi = response.json()

print(gaddafi.keys())
print(gaddafi['response'].keys())
print(type(gaddafi['response']['meta']))
print(gaddafi['response']['meta'])


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'offset': 0, 'time': 40, 'hits': 1069}

In [27]:
print("'The New York times used the name Gaddafi to refer to Muammar Gaddafi", gaddafi['response']['meta']['hits'], "times")


'The New York times used the name Gaddafi to refer to Muammar Gaddafi 1069 times

In [28]:
import requests
response = requests.get("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Kadafi&fq=Libya&api-key=b577eb5b46ad4bec8ee159c89208e220")
kadafi = response.json()
print(kadafi.keys())
print(kadafi['response'].keys())
print(type(kadafi['response']['meta']))
print(kadafi['response']['meta'])


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'offset': 0, 'time': 29, 'hits': 3}

In [29]:
print("'The New York times used the name Kadafi to refer to Muammar Gaddafi", kadafi['response']['meta']['hits'], "times")


'The New York times used the name Kadafi to refer to Muammar Gaddafi 3 times

In [30]:
import requests
response = requests.get("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Qaddafi&fq=Libya&api-key=b577eb5b46ad4bec8ee159c89208e220")
qaddafi = response.json()

print(qaddafi.keys())
print(qaddafi['response'].keys())
print(type(qaddafi['response']['meta']))
print(qaddafi['response']['meta'])


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'offset': 0, 'time': 38, 'hits': 5309}

In [31]:
print("'The New York times used the name Qaddafi to refer to Muammar Gaddafi", qaddafi['response']['meta']['hits'], "times")


'The New York times used the name Qaddafi to refer to Muammar Gaddafi 5309 times

4) What's the title of the first story to mention the word 'hipster' in 1995? What's the first paragraph?


In [32]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q=hipster&begin_date=19950101&end_date=19953112&sort=oldest&api-key=b577eb5b46ad4bec8ee159c89208e220")
hipster = response.json()


print(hipster.keys())
print(hipster['response'].keys())
print(hipster['response']['docs'][0])
hipster_info= hipster['response']['docs']


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'_id': '4fd1ecab8eb7c8105d73e5ad', 'section_name': 'Style', 'source': 'The New York Times', 'headline': {'kicker': 'SURFACING', 'main': 'SOUND'}, 'slideshow_credits': None, 'document_type': 'article', 'pub_date': '1995-02-05T00:00:00Z', 'keywords': [{'value': 'RECORDING EQUIPMENT', 'name': 'subject'}], 'abstract': None, 'multimedia': [], 'lead_paragraph': "Portable record players with built-in speakers, from the 1960's, are the latest points on hipster score cards. In some cases, they are the only way to listen to many of the old LP or 45-r.p.m. recordings still around but not released on cassette or CD. Usually available in white plastic or metal, they can be found in flea markets and secondhand stores. One style has the arm cast in the shape of a cobra. (Don Hogan Charles/The New York Times)", 'word_count': 81, 'snippet': "Portable record players with built-in speakers, from the 1960's, are the latest points on hipster score cards. In some cases, they are the only way to listen to many of the old LP or 45-r.p.m. recordings still around but not released on cassette or...", 'web_url': 'http://www.nytimes.com/1995/02/05/style/surfacing-sound.html', 'print_page': '52', 'subsection_name': None, 'blog': [], 'type_of_material': 'News', 'byline': None, 'news_desk': 'Style Desk'}

In [33]:
print('These articles all had the word hipster in them and were published in 1995') #ordered from oldest to newest
for item in hipster_info:
    print(item['headline']['main'], item['pub_date'])


These articles all had the word hipster in them and were published in 1995
SOUND 1995-02-05T00:00:00Z
The Revenge of the Un-Hip 1995-02-05T00:00:00Z
For Actors, a Casting Call And a Cautionary Note 1995-02-12T00:00:00Z
Terminal Kitsch 1995-02-12T00:00:00Z
From Lumpy Blue Mass To Chic Blue Line 1995-03-05T00:00:00Z
Guys' Stuff (for Guys?) 1995-03-19T00:00:00Z
Mixed Results From 2 Designers 1995-04-06T00:00:00Z
Reviews/Fashion; Cool Rises to Intimidating Heights 1995-04-07T00:00:00Z
Oswald and Mailer: The Eternal Basic Questions 1995-04-25T00:00:00Z
By Design; Westward Ho! 1995-04-25T00:00:00Z

In [34]:
for item in hipster_info:
    if item['headline']['main'] == "SOUND":
        
        print("This is the first article to mention the word hispter in 1995 and was titled:", item['headline']['main'],"and it was publised on:", item['pub_date'])
        print("This is the lead paragraph of", item['headline']['main'],item['lead_paragraph'])


This is the first article to mention the word hispter in 1995 and was titled: SOUND and it was publised on: 1995-02-05T00:00:00Z
This is the lead paragraph of SOUND Portable record players with built-in speakers, from the 1960's, are the latest points on hipster score cards. In some cases, they are the only way to listen to many of the old LP or 45-r.p.m. recordings still around but not released on cassette or CD. Usually available in white plastic or metal, they can be found in flea markets and secondhand stores. One style has the arm cast in the shape of a cobra. (Don Hogan Charles/The New York Times)

5) How many times was gay marriage mentioned in the NYT between 1950-1959, 1960-1969, 1970-1978, 1980-1989, 1990-2099, 2000-2009, and 2010-present?


In [61]:
import requests
response = requests.get('https://api.nytimes.com/svc/search/v2/articlesearch.json?q="gay marriage"&begin_date=19500101&end_date=19593112&api-key=b577eb5b46ad4bec8ee159c89208e220')
marriage_1959 = response.json()

print(marriage_1959.keys())
print(marriage_1959['response'].keys())
print(marriage_1959['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_1959['response']['meta']['hits'], "between 1950-1959")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 51, 'hits': 7587}
___________
Gay marriage was mentioned 7587 between 1950-1959

In [36]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=19600101&end_date=19693112&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_1969 = response.json()

print(marriage_1969.keys())
print(marriage_1969['response'].keys())
print(marriage_1969['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_1969['response']['meta']['hits'], "between 1960-1969")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 63, 'hits': 15899}
___________
Gay marriage was mentioned 15899 between 1960-1969

In [37]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=19700101&end_date=19783112&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_1978 = response.json()

print(marriage_1978.keys())
print(marriage_1978['response'].keys())
print(marriage_1978['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_1978['response']['meta']['hits'], "between 1970-1978")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 37, 'hits': 15539}
___________
Gay marriage was mentioned 15539 between 1970-1978

In [38]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=19800101&end_date=19893112&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_1989 = response.json()

print(marriage_1989.keys())
print(marriage_1989['response'].keys())
print(marriage_1989['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_1989['response']['meta']['hits'], "between 1980-1989")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 41, 'hits': 15119}
___________
Gay marriage was mentioned 15119 between 1980-1989

In [39]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=19900101&end_date=20003112&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_2000 = response.json()

print(marriage_2000.keys())
print(marriage_2000['response'].keys())
print(marriage_2000['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_2000['response']['meta']['hits'], "between 1990-2000")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 48, 'hits': 14751}
___________
Gay marriage was mentioned 14751 between 1990-2000

In [40]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=20000101&end_date=20093112&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_2009 = response.json()

print(marriage_2009.keys())
print(marriage_2009['response'].keys())
print(marriage_2009['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_2009['response']['meta']['hits'], "between 2000-2009")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 33, 'hits': 13641}
___________
Gay marriage was mentioned 13641 between 2000-2009

In [41]:
import requests
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json?q='gay marriage'&begin_date=20100101&end_date=20160609&api-key=b577eb5b46ad4bec8ee159c89208e220")
marriage_2016 = response.json()

print(marriage_2016.keys())
print(marriage_2016['response'].keys())
print(marriage_2016['response']['meta'])
print("___________")
print("Gay marriage was mentioned", marriage_2016['response']['meta']['hits'], "between 2010-present")


dict_keys(['copyright', 'response', 'status'])
dict_keys(['docs', 'meta'])
{'offset': 0, 'time': 31, 'hits': 8727}
___________
Gay marriage was mentioned 8727 between 2010-present

6) What section talks about motorcycles the most?

Tip: You'll be using facets


In [42]:
import requests
response = requests.get("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=motorcycles&facet_field=section_name&api-key=b577eb5b46ad4bec8ee159c89208e220")
motorcycles = response.json()

In [43]:
print(motorcycles.keys())


dict_keys(['copyright', 'response', 'status'])

In [44]:
print(motorcycles['response'].keys())


dict_keys(['docs', 'facets', 'meta'])

In [45]:
print(motorcycles['response']['facets']['section_name']['terms'])


[{'term': 'World', 'count': 1078}, {'term': 'New York and Region', 'count': 580}, {'term': 'U.S.', 'count': 489}, {'term': 'Automobiles', 'count': 345}, {'term': 'Business', 'count': 333}]

In [46]:
motorcycles_info= motorcycles['response']['facets']['section_name']['terms']
print(motorcycles_info)
print("These are the sections that talk the most about motorcycles:")
print("_________________")
for item in motorcycles_info:
    print("The",item['term'],"section mentioned motorcycle", item['count'], "times")


[{'term': 'World', 'count': 1078}, {'term': 'New York and Region', 'count': 580}, {'term': 'U.S.', 'count': 489}, {'term': 'Automobiles', 'count': 345}, {'term': 'Business', 'count': 333}]
These are the sections that talk the most about motorcycles:
_________________
The World section mentioned motorcycle 1078 times
The New York and Region section mentioned motorcycle 580 times
The U.S. section mentioned motorcycle 489 times
The Automobiles section mentioned motorcycle 345 times
The Business section mentioned motorcycle 333 times

In [47]:
motorcycle_info= motorcycles['response']['facets']['section_name']['terms']
most_motorcycle_section = 0
section_name = "" 
for item in motorcycle_info:
    if item['count']>most_motorcycle_section:
        most_motorcycle_section = item['count']
        section_name = item['term']

print(section_name, "is the sections that talks the most about motorcycles, with", most_motorcycle_section, "mentions of the word")


World is the sections that talks the most about motorcycles, with 1078 mentions of the word

7) How many of the last 20 movies reviewed by the NYT were Critics' Picks? How about the last 40? The last 60?

Tip: You really don't want to do this 3 separate times (1-20, 21-40 and 41-60) and add them together. What if, perhaps, you were able to figure out how to combine two lists? Then you could have a 1-20 list, a 1-40 list, and a 1-60 list, and then just run similar code for each of them.


In [48]:
import requests
response = requests.get('http://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=b577eb5b46ad4bec8ee159c89208e220')
movies_reviews_20 = response.json()

print(movies_reviews_20.keys())


dict_keys(['copyright', 'num_results', 'has_more', 'results', 'status'])

In [49]:
print(movies_reviews_20['results'][0])


{'display_title': 'Clown', 'mpaa_rating': 'R', 'headline': 'Review: ‘Clown’ — At Least Bozo Never Ate the Kids', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/18/arts/18CLOWN/18CLOWN-mediumThreeByTwo210.jpg', 'width': 210, 'height': 140, 'type': 'mediumThreeByTwo210'}, 'link': {'suggested_link_text': 'Read the New York Times Review of Clown', 'type': 'article', 'url': 'http://www.nytimes.com/2016/06/18/movies/clown-review-jon-watts.html'}, 'date_updated': '2016-06-17 22:44:33', 'opening_date': None, 'summary_short': 'This horror film, directed by Jon Watts, finds a man putting on a costume — yes, with a red nose — and becoming a possessed killer.', 'critics_pick': 0, 'publication_date': '2016-06-17', 'byline': 'GLENN KENNY'}

In [50]:
critics_pick = 0
not_a_critics_pick = 0
for item in movies_reviews_20['results']:
    print(item['display_title'], item['critics_pick'])
    if item['critics_pick'] == 1:
        print("-------------CRITICS PICK!")
        critics_pick = critics_pick + 1
    else:
        print("-------------NOT CRITICS PICK!")
        not_a_critics_pick = not_a_critics_pick + 1
print("______________________")        
print("There were", critics_pick, "critics picks in the last 20 revies by the NYT")


Clown 0
-------------NOT CRITICS PICK!
Bang Gang: A Modern Love Story 0
-------------NOT CRITICS PICK!
Cosmos 0
-------------NOT CRITICS PICK!
Tickled 1
-------------CRITICS PICK!
Raiders: The Story of the Greatest Fan Film Ever Made 0
-------------NOT CRITICS PICK!
Argentina 0
-------------NOT CRITICS PICK!
Central Intelligence 0
-------------NOT CRITICS PICK!
Department Q: The Keeper of Lost Causes 0
-------------NOT CRITICS PICK!
Department Q: a Conspiracy of Faith 1
-------------CRITICS PICK!
Land and Shade 0
-------------NOT CRITICS PICK!
My Love, Don’t Cross That River 1
-------------CRITICS PICK!
Parched 1
-------------CRITICS PICK!
Seoul Searching 1
-------------CRITICS PICK!
2016 Sundance Film Festival Short Film Tour 0
-------------NOT CRITICS PICK!
Finding Dory 1
-------------CRITICS PICK!
De Palma 0
-------------NOT CRITICS PICK!
Genius 0
-------------NOT CRITICS PICK!
Call Her Applebroog 1
-------------CRITICS PICK!
Careful What You Wish For 0
-------------NOT CRITICS PICK!
Len and Company 1
-------------CRITICS PICK!
______________________
There were 8 critics picks in the last 20 revies by the NYT

In [51]:
import requests
response = requests.get('http://api.nytimes.com/svc/movies/v2/reviews/search.json?offset=20&api-key=b577eb5b46ad4bec8ee159c89208e220')
movies_reviews_40 = response.json()

print(movies_reviews_40.keys())


import requests
response = requests.get('http://api.nytimes.com/svc/movies/v2/reviews/search.json?offset=40&api-key=b577eb5b46ad4bec8ee159c89208e220')
movies_reviews_60 = response.json()

print(movies_reviews_60.keys())


dict_keys(['copyright', 'num_results', 'has_more', 'results', 'status'])
dict_keys(['copyright', 'num_results', 'has_more', 'results', 'status'])

In [52]:
new_medium_list = movies_reviews_20['results'] + movies_reviews_40['results']

In [53]:
print(len(new_medium_list))


40

In [54]:
critics_pick = 0
not_a_critics_pick = 0
for item in new_medium_list:
    print(item['display_title'], item['critics_pick'])
    if item['critics_pick'] == 1:
        print("-------------CRITICS PICK!")
        critics_pick = critics_pick + 1
    else:
        print("-------------NOT CRITICS PICK!")
        not_a_critics_pick = not_a_critics_pick + 1
print("______________________")        
print("There were", critics_pick, "critics picks in the last 40 revies by the NYT")


Clown 0
-------------NOT CRITICS PICK!
Bang Gang: A Modern Love Story 0
-------------NOT CRITICS PICK!
Cosmos 0
-------------NOT CRITICS PICK!
Tickled 1
-------------CRITICS PICK!
Raiders: The Story of the Greatest Fan Film Ever Made 0
-------------NOT CRITICS PICK!
Argentina 0
-------------NOT CRITICS PICK!
Central Intelligence 0
-------------NOT CRITICS PICK!
Department Q: The Keeper of Lost Causes 0
-------------NOT CRITICS PICK!
Department Q: a Conspiracy of Faith 1
-------------CRITICS PICK!
Land and Shade 0
-------------NOT CRITICS PICK!
My Love, Don’t Cross That River 1
-------------CRITICS PICK!
Parched 1
-------------CRITICS PICK!
Seoul Searching 1
-------------CRITICS PICK!
2016 Sundance Film Festival Short Film Tour 0
-------------NOT CRITICS PICK!
Finding Dory 1
-------------CRITICS PICK!
De Palma 0
-------------NOT CRITICS PICK!
Genius 0
-------------NOT CRITICS PICK!
Call Her Applebroog 1
-------------CRITICS PICK!
Careful What You Wish For 0
-------------NOT CRITICS PICK!
Len and Company 1
-------------CRITICS PICK!
Germans & Jews 0
-------------NOT CRITICS PICK!
Puerto Ricans in Paris 0
-------------NOT CRITICS PICK!
Last Cab to Darwin 0
-------------NOT CRITICS PICK!
Now You See Me 2 0
-------------NOT CRITICS PICK!
King Jack 1
-------------CRITICS PICK!
Be Somebody 0
-------------NOT CRITICS PICK!
The Music of Strangers 0
-------------NOT CRITICS PICK!
Therapy for a Vampire 0
-------------NOT CRITICS PICK!
Tikkun 0
-------------NOT CRITICS PICK!
Diary of a Chambermaid 0
-------------NOT CRITICS PICK!
The Conjuring 2 1
-------------CRITICS PICK!
Warcraft 0
-------------NOT CRITICS PICK!
'Til Madness Do Us Part 0
-------------NOT CRITICS PICK!
From Afar 1
-------------CRITICS PICK!
The Fits 1
-------------CRITICS PICK!
Art Bastard 1
-------------CRITICS PICK!
Me Before You 0
-------------NOT CRITICS PICK!
Time to Choose 1
-------------CRITICS PICK!
Andron 0
-------------NOT CRITICS PICK!
Approaching the Unknown 0
-------------NOT CRITICS PICK!
______________________
There were 14 critics picks in the last 40 revies by the NYT

In [55]:
new_big_list = movies_reviews_20['results'] + movies_reviews_40['results'] + movies_reviews_60['results']

In [56]:
print(new_big_list[0])


{'display_title': 'Clown', 'mpaa_rating': 'R', 'headline': 'Review: ‘Clown’ — At Least Bozo Never Ate the Kids', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/18/arts/18CLOWN/18CLOWN-mediumThreeByTwo210.jpg', 'width': 210, 'height': 140, 'type': 'mediumThreeByTwo210'}, 'link': {'suggested_link_text': 'Read the New York Times Review of Clown', 'type': 'article', 'url': 'http://www.nytimes.com/2016/06/18/movies/clown-review-jon-watts.html'}, 'date_updated': '2016-06-17 22:44:33', 'opening_date': None, 'summary_short': 'This horror film, directed by Jon Watts, finds a man putting on a costume — yes, with a red nose — and becoming a possessed killer.', 'critics_pick': 0, 'publication_date': '2016-06-17', 'byline': 'GLENN KENNY'}

In [57]:
print(len(new_big_list))


60

In [58]:
critics_pick = 0
not_a_critics_pick = 0
for item in new_big_list:
    print(item['display_title'], item['critics_pick'])
    if item['critics_pick'] == 1:
        print("-------------CRITICS PICK!")
        critics_pick = critics_pick + 1
    else:
        print("-------------NOT CRITICS PICK!")
        not_a_critics_pick = not_a_critics_pick + 1
print("______________________")        
print("There were", critics_pick, "critics picks in the last 60 revies by the NYT")


Clown 0
-------------NOT CRITICS PICK!
Bang Gang: A Modern Love Story 0
-------------NOT CRITICS PICK!
Cosmos 0
-------------NOT CRITICS PICK!
Tickled 1
-------------CRITICS PICK!
Raiders: The Story of the Greatest Fan Film Ever Made 0
-------------NOT CRITICS PICK!
Argentina 0
-------------NOT CRITICS PICK!
Central Intelligence 0
-------------NOT CRITICS PICK!
Department Q: The Keeper of Lost Causes 0
-------------NOT CRITICS PICK!
Department Q: a Conspiracy of Faith 1
-------------CRITICS PICK!
Land and Shade 0
-------------NOT CRITICS PICK!
My Love, Don’t Cross That River 1
-------------CRITICS PICK!
Parched 1
-------------CRITICS PICK!
Seoul Searching 1
-------------CRITICS PICK!
2016 Sundance Film Festival Short Film Tour 0
-------------NOT CRITICS PICK!
Finding Dory 1
-------------CRITICS PICK!
De Palma 0
-------------NOT CRITICS PICK!
Genius 0
-------------NOT CRITICS PICK!
Call Her Applebroog 1
-------------CRITICS PICK!
Careful What You Wish For 0
-------------NOT CRITICS PICK!
Len and Company 1
-------------CRITICS PICK!
Germans & Jews 0
-------------NOT CRITICS PICK!
Puerto Ricans in Paris 0
-------------NOT CRITICS PICK!
Last Cab to Darwin 0
-------------NOT CRITICS PICK!
Now You See Me 2 0
-------------NOT CRITICS PICK!
King Jack 1
-------------CRITICS PICK!
Be Somebody 0
-------------NOT CRITICS PICK!
The Music of Strangers 0
-------------NOT CRITICS PICK!
Therapy for a Vampire 0
-------------NOT CRITICS PICK!
Tikkun 0
-------------NOT CRITICS PICK!
Diary of a Chambermaid 0
-------------NOT CRITICS PICK!
The Conjuring 2 1
-------------CRITICS PICK!
Warcraft 0
-------------NOT CRITICS PICK!
'Til Madness Do Us Part 0
-------------NOT CRITICS PICK!
From Afar 1
-------------CRITICS PICK!
The Fits 1
-------------CRITICS PICK!
Art Bastard 1
-------------CRITICS PICK!
Me Before You 0
-------------NOT CRITICS PICK!
Time to Choose 1
-------------CRITICS PICK!
Andron 0
-------------NOT CRITICS PICK!
Approaching the Unknown 0
-------------NOT CRITICS PICK!
The Final Master 1
-------------CRITICS PICK!
The God Cells 0
-------------NOT CRITICS PICK!
Gurukulam 0
-------------NOT CRITICS PICK!
The President 0
-------------NOT CRITICS PICK!
Teenage Mutant Ninja Turtles: Out of the Shadows 0
-------------NOT CRITICS PICK!
The Thoughts That Once We Had 1
-------------CRITICS PICK!
The Wailing 1
-------------CRITICS PICK!
The Witness 1
-------------CRITICS PICK!
Popstar: Never Stop Never Stopping 0
-------------NOT CRITICS PICK!
To Life 1
-------------CRITICS PICK!
Princess 1
-------------CRITICS PICK!
The Ones Below 0
-------------NOT CRITICS PICK!
Jia Zhangke, a Guy From Fenyang 1
-------------CRITICS PICK!
Holy Hell 0
-------------NOT CRITICS PICK!
As I AM: The Life and Time$ of DJ AM 0
-------------NOT CRITICS PICK!
Chevalier 0
-------------NOT CRITICS PICK!
The Idol 0
-------------NOT CRITICS PICK!
Presenting Princess Shaw 1
-------------CRITICS PICK!
X-Men: Apocalypse 0
-------------NOT CRITICS PICK!
Alice Through the Looking Glass 0
-------------NOT CRITICS PICK!
______________________
There were 22 critics picks in the last 60 revies by the NYT

8) Out of the last 40 movie reviews from the NYT, which critic has written the most reviews?


In [59]:
medium_list = movies_reviews_20['results'] + movies_reviews_40['results']
print(type(medium_list))
print(medium_list[0])
for item in medium_list:
    print(item['byline'])


<class 'list'>
{'display_title': 'Clown', 'mpaa_rating': 'R', 'headline': 'Review: ‘Clown’ — At Least Bozo Never Ate the Kids', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/18/arts/18CLOWN/18CLOWN-mediumThreeByTwo210.jpg', 'width': 210, 'height': 140, 'type': 'mediumThreeByTwo210'}, 'link': {'suggested_link_text': 'Read the New York Times Review of Clown', 'type': 'article', 'url': 'http://www.nytimes.com/2016/06/18/movies/clown-review-jon-watts.html'}, 'date_updated': '2016-06-17 22:44:33', 'opening_date': None, 'summary_short': 'This horror film, directed by Jon Watts, finds a man putting on a costume — yes, with a red nose — and becoming a possessed killer.', 'critics_pick': 0, 'publication_date': '2016-06-17', 'byline': 'GLENN KENNY'}
GLENN KENNY
STEPHEN HOLDEN
A. O. SCOTT
MANOHLA DARGIS
MANOHLA DARGIS
NEIL GENZLINGER
JEANNETTE CATSOULIS
KEN JAWOROWSKI
KEN JAWOROWSKI
BEN KENIGSBERG
ANDY WEBSTER
GLENN KENNY
JEANNETTE CATSOULIS
BEN KENIGSBERG
A. O. SCOTT
A. O. SCOTT
A. O. SCOTT
GLENN KENNY
NEIL GENZLINGER
ANDY WEBSTER
KEN JAWOROWSKI
ANDY WEBSTER
DANIEL M. GOLD
JEANNETTE CATSOULIS
HELEN T. VERONGOS
ANDY WEBSTER
KEN JAWOROWSKI
MANOHLA DARGIS
A. O. SCOTT
STEPHEN HOLDEN
NEIL GENZLINGER
MANOHLA DARGIS
BEN KENIGSBERG
STEPHEN HOLDEN
MANOHLA DARGIS
STEPHEN HOLDEN
A. O. SCOTT
STEPHEN HOLDEN
NEIL GENZLINGER
BEN KENIGSBERG

In [60]:
all_critics = []
for item in medium_list:
    all_critics.append(item['byline'])
print(all_critics)

unique_medium_list = set(all_critics)
print(unique_medium_list)

print("___________________________________________________")

print("This is a list of the authors who have written the NYT last 40 movie reviews, in descending order:")
from collections import Counter
count = Counter(all_critics)
print(count)

print("___________________________________________________")


print("This is a list of the top 3 authors who have written the NYT last 40 movie reviews:")
count.most_common(1)


['GLENN KENNY', 'STEPHEN HOLDEN', 'A. O. SCOTT', 'MANOHLA DARGIS', 'MANOHLA DARGIS', 'NEIL GENZLINGER', 'JEANNETTE CATSOULIS', 'KEN JAWOROWSKI', 'KEN JAWOROWSKI', 'BEN KENIGSBERG', 'ANDY WEBSTER', 'GLENN KENNY', 'JEANNETTE CATSOULIS', 'BEN KENIGSBERG', 'A. O. SCOTT', 'A. O. SCOTT', 'A. O. SCOTT', 'GLENN KENNY', 'NEIL GENZLINGER', 'ANDY WEBSTER', 'KEN JAWOROWSKI', 'ANDY WEBSTER', 'DANIEL M. GOLD', 'JEANNETTE CATSOULIS', 'HELEN T. VERONGOS', 'ANDY WEBSTER', 'KEN JAWOROWSKI', 'MANOHLA DARGIS', 'A. O. SCOTT', 'STEPHEN HOLDEN', 'NEIL GENZLINGER', 'MANOHLA DARGIS', 'BEN KENIGSBERG', 'STEPHEN HOLDEN', 'MANOHLA DARGIS', 'STEPHEN HOLDEN', 'A. O. SCOTT', 'STEPHEN HOLDEN', 'NEIL GENZLINGER', 'BEN KENIGSBERG']
{'KEN JAWOROWSKI', 'A. O. SCOTT', 'NEIL GENZLINGER', 'MANOHLA DARGIS', 'JEANNETTE CATSOULIS', 'BEN KENIGSBERG', 'HELEN T. VERONGOS', 'GLENN KENNY', 'ANDY WEBSTER', 'STEPHEN HOLDEN', 'DANIEL M. GOLD'}
___________________________________________________
This is a list of the authors who have written the NYT last 40 movie reviews, in descending order:
Counter({'A. O. SCOTT': 6, 'STEPHEN HOLDEN': 5, 'MANOHLA DARGIS': 5, 'KEN JAWOROWSKI': 4, 'ANDY WEBSTER': 4, 'NEIL GENZLINGER': 4, 'BEN KENIGSBERG': 4, 'GLENN KENNY': 3, 'JEANNETTE CATSOULIS': 3, 'HELEN T. VERONGOS': 1, 'DANIEL M. GOLD': 1})
___________________________________________________
This is a list of the top 3 authors who have written the NYT last 40 movie reviews:
Out[60]:
[('A. O. SCOTT', 6)]

In [ ]:


In [ ]:


In [ ]: