{ "cells": [ { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "import dotenv\n", "import os\n", "from datetime import datetime\n", "\n", "dotenv.load_dotenv(\".env\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "params = {\n", " \"api-key\":api_key\n", "}\n", "\n", "result = requests.get(\n", " \"https://api.nytimes.com/svc/books/v3/lists/names.json\",\n", " params=params\n", " )" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "results = result.json()['results']" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'list_name': 'Combined Print and E-Book Fiction',\n", " 'display_name': 'Combined Print & E-Book Fiction',\n", " 'list_name_encoded': 'combined-print-and-e-book-fiction',\n", " 'oldest_published_date': '2011-02-13',\n", " 'newest_published_date': '2025-03-16',\n", " 'updated': 'WEEKLY'}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results[0]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\"combined-print-and-e-book-fiction, \"\n", "\"combined-print-and-e-book-nonfiction, \"\n", "\"hardcover-fiction, \"\n", "\"hardcover-nonfiction, \"\n", "\"trade-fiction-paperback, \"\n", "\"paperback-nonfiction, \"\n", "\"advice-how-to-and-miscellaneous, \"\n", "\"childrens-middle-grade-hardcover, \"\n", "\"picture-books, \"\n", "\"series-books, \"\n", "\"young-adult-hardcover, \"\n", "\"audio-fiction, \"\n", "\"audio-nonfiction, \"\n", "\"business-books, \"\n", "\"graphic-books-and-manga, \"\n", "\"mass-market-monthly, \"\n", "\"middle-grade-paperback-monthly, \"\n", "\"young-adult-paperback-monthly, \"\n" ] } ], "source": [ "for nyt_list in results:\n", " if datetime.strptime(nyt_list['newest_published_date'], \"%Y-%m-%d\").year == 2025:\n", " print('\"' + nyt_list['list_name_encoded'] + ', \"')" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "result = requests.get(\n", " \"https://api.nytimes.com/svc/books/v3/lists/current/graphic-books-and-manga.json\",\n", " params=params\n", " )" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "list_results = result.json()" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "book_results = result.json()['results']['books']" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "book_result_str = \"\"\n", "for ix, book_result in enumerate(book_results):\n", "\n", " rank = book_result.get(\"rank\")\n", " if rank:\n", " book_result_str += f\"rank: {rank}\\n\"\n", "\n", " title = book_result.get(\"title\")\n", " if title:\n", " book_result_str += f\"title: {title}\\n\"\n", "\n", " author = book_result.get(\"author\")\n", " if author:\n", " book_result_str += f\"author: {author}\\n\"\n", "\n", " description = book_result.get(\"description\")\n", " if description:\n", " book_result_str += f\"description: {description}\\n\"\n", "\n", " primary_isbn10 = book_result.get(\"primary_isbn10\")\n", " if primary_isbn10:\n", " book_result_str += f\"primary_isbn10: {primary_isbn10}\\n\"\n", "\n", " primary_isbn13 = book_result.get(\"primary_isbn13\")\n", " if primary_isbn13:\n", " book_result_str += f\"primary_isbn13: {primary_isbn13}\\n\"\n", "\n", " buy_links = book_result.get(\"buy_links\")\n", " if buy_links:\n", " book_result_str += f\"buy_links: \"\n", " for buy_link in buy_links:\n", " book_result_str += f\"{buy_link.get('name')} {buy_link.get('url')}\\n\"\n", "\n", " book_result_str += \"=============================\\n\\n\"\n", "\n", " if ix + 1 == 5:\n", " break" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rank: 1\n", "title: BIG JIM BEGINS\n", "author: Dav Pilkey\n", "description: The 13th book in the Dog Man series. Big Jim has an adventure that brings up the past.\n", "primary_isbn10: 1338896458\n", "primary_isbn13: 9781338896459\n", "buy_links: Amazon https://www.amazon.com/dp/1338896458?tag=thenewyorktim-20\n", "Apple Books https://goto.applebooks.apple/9781338896459?at=10lIEQ\n", "Barnes and Noble https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781338896459\n", "Books-A-Million https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FBIG%2BJIM%2BBEGINS%2FDav%2BPilkey%2F9781338896459\n", "Bookshop.org https://bookshop.org/a/3546/9781338896459\n", "=============================\n", "\n", "rank: 2\n", "title: THE SCARLET SHEDDER\n", "author: Dav Pilkey\n", "description: The 12th book in the Dog Man series. Dog Man finds himself back on his hind legs after being sprayed by a skunk.\n", "primary_isbn10: 1338896431\n", "primary_isbn13: 9781338896435\n", "buy_links: Amazon https://www.amazon.com/dp/1338896431?tag=thenewyorktim-20\n", "Apple Books https://goto.applebooks.apple/9781338896435?at=10lIEQ\n", "Barnes and Noble https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781338896435\n", "Books-A-Million https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BSCARLET%2BSHEDDER%2FDav%2BPilkey%2F9781338896435\n", "Bookshop.org https://bookshop.org/a/3546/9781338896435\n", "=============================\n", "\n", "rank: 3\n", "title: DOG MAN\n", "author: Dav Pilkey\n", "description: A dog’s head is combined with a policeman’s body to create this hybrid supercop hound.\n", "primary_isbn10: 1338741039\n", "primary_isbn13: 9781338741032\n", "buy_links: Amazon https://www.amazon.com/dp/1338741039?tag=thenewyorktim-20\n", "Apple Books https://goto.applebooks.apple/9781338741032?at=10lIEQ\n", "Barnes and Noble https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781338741032\n", "Books-A-Million https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDOG%2BMAN%2FDav%2BPilkey%2F9781338741032\n", "Bookshop.org https://bookshop.org/a/3546/9781338741032\n", "=============================\n", "\n", "rank: 4\n", "title: ESCAPING PERIL\n", "author: Tui T. Sutherland.\n", "description: The eighth book in the Wings of Fire graphic novel series. Peril's sense of loyalty becomes tested.\n", "primary_isbn10: 1339001233\n", "primary_isbn13: 9781339001234\n", "buy_links: Amazon https://www.amazon.com/dp/1339001233?tag=thenewyorktim-20\n", "Apple Books https://goto.applebooks.apple/9781339001234?at=10lIEQ\n", "Barnes and Noble https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781339001234\n", "Books-A-Million https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FESCAPING%2BPERIL%2FTui%2BT.%2BSutherland.%2F9781339001234\n", "Bookshop.org https://bookshop.org/a/3546/9781339001234\n", "=============================\n", "\n", "rank: 5\n", "title: TWENTY THOUSAND FLEAS UNDER THE SEA\n", "author: Dav Pilkey\n", "description: The 11th book in the Dog Man series. Piggy returns and the Supa Buddies are sabotaged.\n", "primary_isbn10: 1338801910\n", "primary_isbn13: 9781338801910\n", "buy_links: Amazon https://www.amazon.com/dp/1338801910?tag=thenewyorktim-20\n", "Apple Books https://goto.applebooks.apple/9781338801910?at=10lIEQ\n", "Barnes and Noble https://www.anrdoezrs.net/click-7990613-11819508?url=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2F%3Fean%3D9781338801910\n", "Books-A-Million https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTWENTY%2BTHOUSAND%2BFLEAS%2BUNDER%2BTHE%2BSEA%2FDav%2BPilkey%2F9781338801910\n", "Bookshop.org https://bookshop.org/a/3546/9781338801910\n", "=============================\n", "\n", "\n" ] }, { "data": { "text/plain": [ "3737" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(book_result_str)\n", "len(book_result_str)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "agents_env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" } }, "nbformat": 4, "nbformat_minor": 2 }