Some warning for almost-due library books

There was no email waiting for me when I woke up this morning, which meant something went wrong with my library loan tracking system. My wife and I are supposed to get an email every morning that summarizes the status of all of the family’s library “doings”: the items checked out and on hold for us and our kids. Something had caused the script to fail.

I soon discovered that the library had changed the URL for its login page, leading to an error thrown by the Python mechanize module. I went to the library site and clicked around until I got to the new login page, plugged its URL into the script, and all was right with the world. Except…

Except I’d been thinking for a while that the script needed a new feature. It’s always delivered an HTML email with nicely-formatted tables of the items checked out and on hold.

iPhone email of items checked out.

Checked-out items that are due or overdue and on-hold items that are ready to be picked up are given a pink background to make them easier to see.

iPhone email of items on hold. Two are ready for pickup.

What I’ve been thinking it could use is some other highlighting of the items that are due within the next couple of days. The motivation for this script is to allow my wife and me to make better use of our trips to the library; highlighting the almost due items would be a better reminder than just the due date in the first column.

So I’ve modified the script to use a light yellow background for items that are due in the next two days.

iPhone email of items due soon.

(No, the highlighted items above aren’t due in two days. Because we didn’t have anything due that soon, I used a seven-day lookahead while debugging the script. The screenshot was taken before I reduced the lookahead to two days.)

All the code, which consists of

are in this GitHub repository. The Python script uses both the aforelinked mechanize module and the Beautiful Soup module.1

The script works by screen scraping, so the details are specific to our local library, but the ideas could probably be adapted to other libraries. I’ve written about this system in a few previous posts. If you’re interested in how it works, start here and work your way backward through the links to earlier iterations.

  1. I’m using the word “module” here instead of the more standard word “library” to avoid confusion with the brick and mortar library.