-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function to get best-selling books from NYT
- Loading branch information
1 parent
2dbf9f0
commit 0c5c3e9
Showing
5 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
USER_ID=19514847 | ||
USER_ID=19514847 | ||
NYT_KEY='123123' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from config import NYT_KEY | ||
import requests | ||
import pandas as pd | ||
from get_generic_book import fetch_book_data_from_isbn13 | ||
from format_data import save_to_csv, save_to_csv_as_is | ||
|
||
# Set the parameters to get books from New York Times Best Seller List | ||
def set_parameters(): | ||
base_nyt_url = 'https://api.nytimes.com/svc/books/v3/lists/full-overview.json' | ||
nyt_url = f'{base_nyt_url}?api-key={NYT_KEY}' | ||
return nyt_url | ||
|
||
# Get the books from the API | ||
def get_books(nyt_url): | ||
best_sellers = [] | ||
response = requests.get(nyt_url) | ||
if response.status_code == 200: # Check so status is 200 | ||
data = response.json() | ||
for document in data['results']['lists']: # Nestle down in the API | ||
book_info = document.get('books', []) # Get the book data | ||
for b in book_info: | ||
# Save some data from the NYT API | ||
best_sellers.append([b.get('primary_isbn13'), b.get('title').title(), b.get('author')]) | ||
return best_sellers[:100] # Return only 100 first books |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters