bookISBN2Task

In the UK, the average adult reads approximately three books per year, according to a recent poll by YouGov. However, 40% of Britons haven’t read a single book in the last 12 months. That I have read on average 19 books a year puts me very much in the upper echelons of readers in the UK. My wife, on the other hand, averages 126 a year (that’s one every three days) and very much puts me in the shade with her average!

Too Many Books

I suffer from a couple of problems where books are concerned. Firstly, books (that I’d like to read) are being published at a rate faster than I can read them, and secondly, I have a problem whereby if I see an autobiography of a contemporary musician, I have to have it. This all means that I have a very large backlog of books to read, and occasionally, I’d like to re-read some favourites too.

Enter bookISBN2Task

I also suffer from not remembering just what books I own and what I might want to read next – enter bookISBN2Task.

I decided to write a simple little app that I could use to scan book bar codes and then record that book on my reading list. I am aware that I could do that using something like GoodReads but I didn’t want to do that for a few reasons: 

  • I didn’t want to be tied in to the Amazon ecosystem for this
  • I keep my reading list on Remember the Milk
  • I wanted the challenge of writing it myself.

This simple little app uses the Quagga library to scan a barcode which is then decoded and sent to Open Library to look up the details. You are then given then details of the book which you can either add to your reading list or scan another code. At present supported is both Remember the Milk and a simple csv which you can also view through the app.

Adding Your Own Hooks

It’s relatively straightforward to add your own hooks into another service. For example, I’d quite like to update a tab on a Google Sheet or maybe you’d like to record your list elsewhere. If you edit the app.js file you will find a block of code as follows:

// Send book details to the server
if (readButton) {
  readButton.addEventListener("click", () => {
    recordDetails("csv");
    recordDetails("task");
  });
}

This works by calling the recordDetails function passing the suffix of the php script to call. For example the CSV script is called record_csv.php. To add another hook create a php file call, for example, record_sheets.php and add a further line to the readButton section called recordDetails("sheets"). Then when you press the “Add to Reading List” button the hook will trigger and your function will be called being passed the following payload:

  • Title
  • Author(s)
  • Subject (the main genre of the book)
  • Link to the book’s entry on Open Library.

You can parse this incoming data as follows and then process it as you need.

    // Get the raw POST data
    $input = file_get_contents('php://input');
    $data = json_decode($input, true);

    // Validate the received data
    if (isset($data['title'], $data['authors'], $data['url'])) {
        $title = $data['title'];
        $authors = $data['authors'];
        $url = $data['url'];
        $subject = $data['subject'];

As you can see from the image at the bottom of the page the subject isn’t all that useful so you may want to suppress that.

Still Overwhelmed!

Of course, this doesn’t help me read any more than I am already but it does help me get some order into my reading list which should help me prioritise my reading going forward and that’s good enough for me.

You can view and download the code on my Github page here.

Leave a Reply

Your email address will not be published. Required fields are marked *