avatar Bite 221. Parse best selling lists using the NY Times API

NY Times best seller list at the time of writing this BiteIn this Bite you are going to parse NY Times Best Seller Lists using The New York Times Developer Network.

This is the endpoint you will use: https://api.nytimes.com/svc/books/v3/lists/current/hardcover-nonfiction.json?api-key=yourkey (the tests also use hardcover-fiction.json).

Feel free to create an account and obtain an API key to try this out locally. To work with static data we've mocked out the response in the tests.

Code get_best_seller_titles below, for the non-fiction best seller list, the function should return the following list of tuples:

[
  ('BETWEEN THE WORLD AND ME', 86),
  ('EDUCATED', 79),
  ('BECOMING', 41),
  ('THE SECOND MOUNTAIN', 18),
  ('THE PIONEERS', 16),
  ('MAYBE YOU SHOULD TALK TO SOMEONE', 14),
  ('UNFREEDOM OF THE PRESS', 14),
  ('RANGE', 9),
  ('THREE WOMEN', 7),
  ('TRICK MIRROR', 3),
  ('HOW TO BE AN ANTIRACIST', 2),
  ('KOCHLAND', 2),
  ('THANK YOU FOR MY SERVICE', 1),
  ('THE OUTLAW OCEAN', 1),
  ('GODS OF THE UPPER AIR', 1)
]

Keep this script at hand, maybe you can run it in a few months and compare the results. Or collect it weekly or monthly and start plotting the data?

Have fun and learn more Python and APIs!

Login and get coding
go back Intermediate level
Bitecoin 3X

92 out of 95 users completed this Bite.
Will you be Pythonista #93 to crack this Bite?
Resolution time: ~51 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.71 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help