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


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

In [132]:
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(['results', 'copyright', 'status', 'last_modified', 'num_results'])

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


<class 'dict'>

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


<class 'list'>

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


20

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


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

In [137]:
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 [138]:
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 [139]:
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(['results', 'copyright', 'status', 'last_modified', 'num_results'])

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


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

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

In [142]:
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 [143]:
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 [144]:
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 [145]:
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 [146]:
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 [147]:
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 [148]:
print(best_seller.keys())


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

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


53

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

In [151]:
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 [152]:
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 [153]:
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 [154]:
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', 'status', 'response'])
{'docs': [], 'meta': {'hits': 0, 'time': 15, 'offset': 0}}
dict_keys(['docs', 'meta'])
[]

In [155]:
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 [156]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'hits': 1019, 'time': 45, 'offset': 0}

In [157]:
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 1019 times

In [158]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'hits': 3, 'time': 19, 'offset': 0}

In [159]:
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 [160]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
<class 'dict'>
{'hits': 5252, 'time': 54, 'offset': 0}

In [161]:
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 5252 times

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


In [162]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'abstract': None, 'subsection_name': None, 'keywords': [{'value': 'RECORDING EQUIPMENT', 'name': 'subject'}], 'web_url': 'http://www.nytimes.com/1995/02/05/style/surfacing-sound.html', 'news_desk': 'Style Desk', 'blog': [], '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...", 'source': 'The New York Times', 'print_page': '52', 'section_name': 'Style', 'multimedia': [], 'type_of_material': 'News', 'slideshow_credits': None, 'document_type': 'article', '_id': '4fd1ecab8eb7c8105d73e5ad', 'headline': {'kicker': 'SURFACING', 'main': 'SOUND'}, '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, 'pub_date': '1995-02-05T00:00:00Z', 'byline': None}

In [163]:
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 [164]:
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 [165]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 7406, 'time': 35, 'offset': 0}
___________
Gay marriage was mentioned 7406 between 1950-1959

In [166]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 15601, 'time': 43, 'offset': 0}
___________
Gay marriage was mentioned 15601 between 1960-1969

In [188]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 15241, 'time': 36, 'offset': 0}
___________
Gay marriage was mentioned 15241 between 1970-1978

In [189]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 14821, 'time': 47, 'offset': 0}
___________
Gay marriage was mentioned 14821 between 1980-1989

In [190]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 14453, 'time': 249, 'offset': 0}
___________
Gay marriage was mentioned 14453 between 1990-2000

In [191]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 13351, 'time': 33, 'offset': 0}
___________
Gay marriage was mentioned 13351 between 2000-2009

In [192]:
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', 'status', 'response'])
dict_keys(['docs', 'meta'])
{'hits': 8500, 'time': 34, 'offset': 0}
___________
Gay marriage was mentioned 8500 between 2010-present

6) What section talks about motorcycles the most?

Tip: You'll be using facets


In [193]:
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 [194]:
print(motorcycles.keys())


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

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


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

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


[{'count': 1032, 'term': 'World'}, {'count': 574, 'term': 'New York and Region'}, {'count': 474, 'term': 'U.S.'}, {'count': 367, 'term': 'Automobiles'}, {'count': 322, 'term': 'Business'}]

In [197]:
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")


[{'count': 1032, 'term': 'World'}, {'count': 574, 'term': 'New York and Region'}, {'count': 474, 'term': 'U.S.'}, {'count': 367, 'term': 'Automobiles'}, {'count': 322, 'term': 'Business'}]
These are the sections that talk the most about motorcycles:
_________________
The World section mentioned motorcycle 1032 times
The New York and Region section mentioned motorcycle 574 times
The U.S. section mentioned motorcycle 474 times
The Automobiles section mentioned motorcycle 367 times
The Business section mentioned motorcycle 322 times

In [198]:
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 1032 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 [199]:
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(['has_more', 'copyright', 'status', 'results', 'num_results'])

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


{'publication_date': '2016-06-09', 'date_updated': '2016-06-11 12:44:33', 'summary_short': 'In the documentary “De Palma,” Mr. De Palma explores his muse, and the juxtaposition of images from both of their works goes beyond glib shorthand.', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/10/arts/10DEPALMA/10DEPALMA-mediumThreeByTwo210.jpg', 'height': 140, 'type': 'mediumThreeByTwo210', 'width': 210}, 'opening_date': None, 'critics_pick': 0, 'display_title': 'De Palma', 'headline': 'Review: Brian De Palma Says He Is Hitchcock’s True Heir', 'mpaa_rating': 'R', 'link': {'url': 'http://www.nytimes.com/2016/06/10/movies/review-de-palma-documentary.html', 'suggested_link_text': 'Read the New York Times Review of De Palma', 'type': 'article'}, 'byline': 'A. O. SCOTT'}

In [201]:
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")


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!
______________________
There were 6 critics picks in the last 20 revies by the NYT

In [211]:
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(['has_more', 'copyright', 'status', 'results', 'num_results'])
dict_keys(['has_more', 'copyright', 'status', 'results', 'num_results'])

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

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


40

In [221]:
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")


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!
______________________
There were 15 critics picks in the last 40 revies by the NYT

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

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


{'publication_date': '2016-06-09', 'date_updated': '2016-06-11 12:44:33', 'summary_short': 'In the documentary “De Palma,” Mr. De Palma explores his muse, and the juxtaposition of images from both of their works goes beyond glib shorthand.', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/10/arts/10DEPALMA/10DEPALMA-mediumThreeByTwo210.jpg', 'height': 140, 'type': 'mediumThreeByTwo210', 'width': 210}, 'opening_date': None, 'critics_pick': 0, 'display_title': 'De Palma', 'headline': 'Review: Brian De Palma Says He Is Hitchcock’s True Heir', 'mpaa_rating': 'R', 'link': {'url': 'http://www.nytimes.com/2016/06/10/movies/review-de-palma-documentary.html', 'suggested_link_text': 'Read the New York Times Review of De Palma', 'type': 'article'}, 'byline': 'A. O. SCOTT'}

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


60

In [215]:
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")


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!
Unlocking the Cage 0
-------------NOT CRITICS PICK!
Weiner 1
-------------CRITICS PICK!
Maggie's Plan 1
-------------CRITICS PICK!
Kaili Blues 0
-------------NOT CRITICS PICK!
Manhattan Night 0
-------------NOT CRITICS PICK!
The Other Side 1
-------------CRITICS PICK!
Almost Holy 0
-------------NOT CRITICS PICK!
The Angry Birds Movie 0
-------------NOT CRITICS PICK!
Ma Ma 0
-------------NOT CRITICS PICK!
A Moment of Silence 0
-------------NOT CRITICS PICK!
Welcome to Happiness 0
-------------NOT CRITICS PICK!
Neighbors 2: Sorority Rising 0
-------------NOT CRITICS PICK!
Pervert Park 0
-------------NOT CRITICS PICK!
Phantom Detective 0
-------------NOT CRITICS PICK!
O.J.: Made in America 1
-------------CRITICS PICK!
______________________
There were 20 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 [216]:
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'>
{'publication_date': '2016-06-09', 'date_updated': '2016-06-11 12:44:33', 'summary_short': 'In the documentary “De Palma,” Mr. De Palma explores his muse, and the juxtaposition of images from both of their works goes beyond glib shorthand.', 'multimedia': {'src': 'https://static01.nyt.com/images/2016/06/10/arts/10DEPALMA/10DEPALMA-mediumThreeByTwo210.jpg', 'height': 140, 'type': 'mediumThreeByTwo210', 'width': 210}, 'opening_date': None, 'critics_pick': 0, 'display_title': 'De Palma', 'headline': 'Review: Brian De Palma Says He Is Hitchcock’s True Heir', 'mpaa_rating': 'R', 'link': {'url': 'http://www.nytimes.com/2016/06/10/movies/review-de-palma-documentary.html', 'suggested_link_text': 'Read the New York Times Review of De Palma', 'type': 'article'}, 'byline': '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
GLENN KENNY
NEIL GENZLINGER
HELEN T. VERONGOS
BEN KENIGSBERG
GLENN KENNY
JEANNETTE CATSOULIS
GLENN KENNY
ANDY WEBSTER
A. O. SCOTT
HELEN T. VERONGOS
JEANNETTE CATSOULIS
ANDY WEBSTER
GLENN KENNY
KEN JAWOROWSKI
ANDY WEBSTER

In [217]:
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(3)


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

In [ ]:


In [ ]:


In [ ]: