December 1, 2010 at 9:25 PM by Dr. Drang
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.
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.
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.
(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
- the main Python script that queries the library and generates the HTML message,
- the shell script that pipes the output to sendmail (actually postfix using “sendmail” as an alias) for mailing, and
- a launchd plist file for scheduling the messages,
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.
I’m using the word “module” here instead of the more standard word “library” to avoid confusion with the brick and mortar library. ↩︎