Automating My Reading List: A Case Study in the Versatility of Text Files

I try to keep things simple. Back in 1996 when I started keeping a list of the books I read, I did so using a plain text file. I was very much into Linux, which, at the time, was to computer geeks what model trains were to train enthusiasts. So at the beginning of January 1996, I started a text file called “reading.txt” and began keeping a list of the books I read. I kept my rules for the text file fairly simple as well. They boiled down to this:

  1. One book per line.
  2. Record only those books that I actually finished reading.
  3. Capture the title, author, and the date that I finished reading the book.

That was it. Eighteen years later, that text file still exists. Today, it has 558 books listed in it. It has a few refinements as well, but they are all fairly simple. When I first started keeping my list there were no e-books of note. Audible did not exist. These days, I have 4 symbols I will add to the end of a title, that provide a little more information:

  • * for a book that was a particularly good one
  • ^ for a book that I’ve read more than once.
  • + if I read the e-book version.
  • @ if I listened to the audio book.

A quick glance at a section of my reading.txt file, therefore, would look like this:

The Wind Through the Keyhole@* by Stephen King (11/5/2013)
Starhawk@ by Jack McDevitt (11/9/2013)
Old Mars+ edited by Gardner Dozois and George R. R. Martin (11/10/2013)
The Langoliers@ by Stephen King (11/15/2013)

When I started using Dropbox, I put this file in my Public dropbox folder so that I could easily access it from anywhere, but also others who wanted to see it could access it as well. Because the file is plain-text, it requires no special tools to look at it. You can look at it in a web browser. You can open it with Notepad. You cat cat it from a UNIX command line. Any tool you prefer will work with plain text.

When I started using WordPress, I created a version of this list as a page in WordPress. That was convenient because I now had a nicely formatted listing of what I’ve read to which I could point people. But it was also inconvenient in the sense that I had to keep two lists up-to-date, my reading.txt file and my WordPress page.

Not any more. Yesterday, I automated the process entirely so that my reading.txt file is the authoritative source for my reading list. Any updates to that file are now automatically reflected in WordPress.

Automating my reading list

The beauty of text files rests in their simplicity. They may not look as pretty as a Word document, but they are far more versatile. I thought I’d describe how I automated my reading list so that updates in my reading.txt file appear on my WordPress reading list page as an example of the kind of automation text files allow.

1. Public availability.

The first step was to make sure that my reading.txt file was available publicly. This wasn’t a problem since I’ve already had the file on Dropbox for some time. With dropbox, you can get a URL for any file. So grabbed the URL for my reading.txt file on Dropbox as a first step.

2. Create a custom shortcode in WordPress.

The next step was to add a custom shortcode to WordPress. For those who don’t know, shortcodes in WordPress are substitution. You insert a shortcode somewhere in your post or page and it is replaced by something else. In the case of my reading list I created a shortcode called “ReadingList” and when I insert it into a page or post, it expands to my current reading list.

This does require a little programming knowledge, but I kept my code fairly simple. I wrote just enough to parse out the title, author, and date of the book so that I could format it as a numbered list. I also parsed out my symbols so that I could adjust the formatting for favorite books, or color Audible books different from e-books, etc.

Incidentally, I did this as part of my child-theme in such a way that it will not break when my theme is upgraded.

3. Add the shortcode to a page or post.

Finally, I added the shortcode to my reading list page. The entire text of my reading list page now looks like this:

Reading List Text

When you actually go to my reading list, what you see is the expanded list, pulled directly from my reading.txt file on Dropbox, and formatted using the code I wrote for my WordPress shortcode function:

Reading List Page

The power of automation with text files

It used to be that when I finished a book, I’d update my reading.txt file, and then, go into WordPress and update my reading list page there. Updating the reading.txt file takes all of 20 seconds. Updating the WordPress page takes longer, especially if I was doing it from my iPhone.

But that is no longer the case. Now, all I do is update my reading.txt file and my WordPress page is instantly updated–because it is pulling from the same source!

Updating the text file is a breeze from my iMac or my Windows laptop. But now, it is even faster from my iPhone. That’s because I’ve taken advantage of some automation capabilities in the Drafts App to make updates easy. Here is how this works. When I want to add a book to my list, I open the Drafts app, type in the title, author and date, and then select a pre-defined action I created, in this case the action is called “Add to reading list.” Here is what it looks like on my phone:

Drafts App

The “add to reading list” action uses the “Append to Dropbox” action that the Drafts App has to add a line to a file in Dropbox. In this case, the file is my reading.txt file.

Other possibilities

I am working on a command-line interface for my reading list that will allow me to easily parse the lists in different ways. For instance, see all of the books I’ve read this year, or in 1998; or show all of the Isaac Asimov books I’ve read.

Of course, most of these are easily do-able with basic command line functions. For instance, to see all of the Stephen King books I’ve read I can do this:

grep "Stephen King" reading.txt

which will return a list of those lines from my reading.txt file that contain the term “Stephen King.” If I want to know how many Stephen King books I’ve read, I can do this:

grep "Stephen King" reading.txt | wc -l

which does the same thing as above, only pipes the results through the wc command (word count) and counts the lines. Since I only have one book per line, the resulting number is the number of books I’ve read by Stephen King. In this case, it is 57.

I recently created a biblio.txt file on Dropbox. This contains a bibliography of all of my published fiction and nonfiction. I am working on a shortcode for WordPress for this as well so that my current Bibliography page, which is manually maintained, can be automated in the same way I’ve automated my reading list.


I’ve also recently switched back to todo.txt as my to-do list manager. This is also entirely text-based and because of that allows for some cool automation while maintaining  simplicity in my to-do list system. I’ll discuss that in another post.

Enjoy these posts? – Tell a friend

Recommending readers is one of the highest compliments you can pay to a writer. If you enjoy what you read here, or you find the posts useful, tell a friend! Find me online here:

Twitter | Facebook | Google+ | Blog | RSS

Or use one of the share buttons below. Thanks for reading!

5 comments

  1. Whilst I like the simplicity of a text file, I think I would prefer this information in Evernote as I’ve converted to your use of a Timeline.

    What I suppose you could do would be to write a script to scan the text file and if it spots a difference create a new note using the Evernote API ?

  2. Couldn’t you use the date timestamp in Drafts to avoid having to enter the TextExpander code yourself? I’ve just set up my own reading list like yours (two books so far 🙂 and that’s how I did it.

    Is there any chance you’d share your shortcode for the WordPress blog?

    Thanks!

    1. Heather, great idea! I hadn’t thought of that but I’ve updated my Drafts action after your fine suggestion. As soon as I have a few spare cycles, I’ll share the code for my shortcode for my reading list.

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.