Skip to content

How to build a book summary AI for your Amazon wishlist using OpenAI, Airtable and Simplescraper

OpenAI, Airtable and Simplescraper image cover


If you're like most people you probably have an Amazon wishlist full of books that you hope to read one day. At current count my wishlist contains 1,327 books.

As the list grows the question becomes where to begin, and what's this book about again?

The problem is that an Amazon wishlist is not a great place to organize a large number of books. There's no tagging, descriptions or decent sorting options. The solution then is to break your books free of the Amazon wishlist and add helpful context to them - transforming your wishlist into a browsable library.

For example, what if we took something like this:

image-20221222140317862

And turned it into something like this:

image-20221222195038613

Imagine how much easier it is to organize, filter and find books to read this way? Like your own personal Blinkist, but for the books that you care about.

So we have two goals:

  • Move your reading list to a system that makes organizing and filtering the books simple

  • Enrich the list by summarizing each book, including themes, key quotes and category tags

The first goal can be accomplished using Simplescraper, a no-code data extraction tool, and Airtable, a database and app builder. The second goal sounds rather tedious and would take a long time to do at scale (take my word for it, I tried). Fortunately for us, OpenAI have created an AI that's very good at this task, and faster too.

In this guide we'll combine these tools together to super power your reading list - let's get started!

Step 1: Copy your Amazon wishlist to Airtable via Simplescraper

In this step you'll share your Amazon wishlist to Airtable using Simplescraper. No-code is required for this step, just a few clicks and we're done.

  • In Amazon, navigate to your Amazon wishlists (you can find them here: https://www.amazon.com/hz/wishlist/ls) and click 'More' in the top-right corner of the list you wish to export. Click Manage lists from the menu and in the popup that appears select 'Shared' as the Privacy option. With this setting only people you share the link with can view your lists


    image-20221221164641107
  • Copy the URL of your Amazon wishlist to your clipboard

  • Navigate to the following link to save the Amazon wishlist scrape recipe to your Simplescraper account: https://simplescraper.io/?sharedRecipe=bzCzJmJHRKqHTIOvJhVD. Click the 'Use in a new recipe' button and enter the Amazon wishlist URL that you saved in the previous step and save the recipe

image-20221221172355881

  • To confirm that everything's working, click run recipe and wait for the results - the list of your books should appear after a few seconds

  • Now connect to Airtable by clicking on the integrations tab and completing the Airtable section. A full guide is here: https://simplescraper.io/docs/scraping-data-into-airtable/. Once completed it should look like this:


image-20221222115929076

  • To save time here's an Airtable template with all the fields already created: https://airtable.com/shrWpaY7OU8wo54mP. All you need to do is copy the template to one of your Airtable bases and add the Base ID to Simplescraper

  • Now that you've connected Simplescraper to Airtable, click 'run recipe' again and wait for the task to complete. Once completed, navigate to your Airtable table and it should be populated with the contents of your Amazon wishlist:


image-20221221205845798

And that's step 1 complete. You've freed your book list from Amazon. Next let's use AI to enrich the list of books and make them easier to organize.

Step 2: Use OpenAI to summarize, categorize, tag and provide quotes for all of the books in your list

Having our reading list in Airtable is nice - we can sort and use different views to rearrange the data. But it's still just a list of books. What's needed is more context that will allow us to understand what each book is about and decide what to read next. Let's add the following information:

  • Summary: a few paragraphs about the book's contents
  • Quotes from the book: a sample of the writing and key excerpts
  • Category tags: short, filterable words describing the book's topic, genre or theme
  • Book lessons: what one will learn from reading the book

With this additional information, deciding what to read will become simple, and being able to filter and search by tags like business, self-development, fiction etc. will make organizing much easier.

To get started, in Airtable click on extensions, then 'Add an extension' and choose the scripting extension.


image-20221222101255087

Then in the scripting area, paste this code:


javascript
// define variables
let tableName = "amazon wishlist";
let viewName = "Grid view";
let openaiUrl = "https://api.openai.com/v1/completions";
let apiKey = "sk-addyourAPIkey"; // replace with your openAI API key: https://beta.openai.com/account/api-keys

let table = base.getTable(tableName);
let view = table.getView(viewName);

// prompt user to pick a record 
let record = await input.recordAsync('Select a book to summarize', table);
let recordId = record.id;

// get values from record
let bookTitle = record.getCellValue("title");
let bookAuthor = record.getCellValue("author");
bookAuthor = bookAuthor.split("(")[0]; // handle (Kindle Edition) etc in author name

// compose prompt for openAI
let prompt = "Provide detailed yet concise bullet-point summary of " + bookTitle + " " + bookAuthor + "in exactly this format: Long-Form Summary: Themes: Lessons from Reading the Book: Category Tags: Key Quotes:";

async function sendRequest(prompt) {

  try {

    // setup openAI request
    let body = {
      "prompt": prompt,
      "temperature": 0.7,
      "max_tokens": 600,
      "model": "text-davinci-003",
      "top_p": 1.0,
      "frequency_penalty": 0.0,
      "presence_penalty": 0.0
    }


    let response = await fetch(openaiUrl, {
      method: 'POST',
      body: JSON.stringify(body),
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + apiKey,
      }
    });

    let data = await response.json();
    return data;

  } catch (err) {
    console.log("sendRequest err: ", err);
  }

}


function convertResponseToObject(data) {

  // copy response data to variables
  if (data && data.choices) {
    let responseText = data.choices[0].text;
    console.log("responseText: ", responseText);

    let bookSummary = responseText.split("Long-Form Summary:") ? responseText.split("Themes:")[0].replace("Long-Form Summary:", "").trim() : null;
    let bookThemes = responseText.split("Themes:") ? responseText.split("Themes:")[1].split("Lessons from Reading the Book:")[0].trim() : null;
    let bookLessons = responseText.split("Lessons from Reading the Book:") ? responseText.split("Lessons from Reading the Book:")[1].split("Category Tags:")[0].trim() : null;
    let bookTags = responseText.split("Category Tags:") ? responseText.split("Category Tags:")[1].split("Key Quotes:")[0].trim() : null;
    let bookQuotes = responseText.split("Key Quotes:") ? responseText.split("Key Quotes:")[1].trim() : null;

    let responseObj = {};
    responseObj.bookSummary = bookSummary;
    responseObj.bookThemes = bookThemes;
    responseObj.bookLessons = bookLessons;
    responseObj.bookTags = bookTags;
    responseObj.bookQuotes = bookQuotes;

    return responseObj;

  } else {
    return null;
  }
}


async function updateRecord(recordId, responseObj) {

  let updateResponse = await table.updateRecordAsync(recordId, {
    "bookSummary": responseObj.bookSummary,
    "bookThemes": responseObj.bookThemes,
    "bookLessons": responseObj.bookLessons,
    "bookTags": responseObj.bookTags,
    "bookQuotes": responseObj.bookQuotes,
  });

  console.log("updateResponse: ", updateResponse);
}


// call functions
let data = await sendRequest(prompt);
let responseObj = convertResponseToObject(data);
await updateRecord(recordId, responseObj);

The code requires only one change: add your own OpenAI API Key on line 5. Your API key can be found here: https://beta.openai.com/account/api-keys.

Once that's done, click the blue run button and then select one of your books from the pop-up menu. The script will run and return data that looks like this:

image-20221222103419101

That means everything's working!

The final step is to create a button so that we can call the script directly from any Airtable record. To do that add a new field in Airtable, choose button type, and choose Run script as the action. Then in the Extension section select the script that you just created and then click save

image-20221222112002793

And we're done. Each record now has a dedicated 'Get book summary' button. Click that to instantly generate a book summary's, quotes, tags and additional information, and make deciding what to read next a little easier.






Links in this article:

Build with Simplescraper

Turn websites into structured data in seconds.