Reading Schedule Generator

[http://farm1.staticflickr.com/119/281194868_23e0c0e390_n.jpg] October 2017 Update: I regret that I let this article get badly out of whack with reality. Notably, most of the links to my code, which were on the old UNH "pubpages" server, went stale when I retired. In addition, I've cleaned up the code some and fixed a nasty Daylight Savings Time-related bug. I hope. Further notes at the bottom of the article.

Note: this post is out of whack with normal Pun Salad content. Only recommended for:

  1. computer geeks who (like me) tend to approach everyday issues by asking: how could I write code to make this easier?; or
  2. psychologists who might be interested in whatever mental aberration causes the behavior exhibited in (a).

A few years back I noticed I was doing a miserable job of reading the magazines to which I was subscribed; the new issue would show up and I would have just read few if any articles in the previous one.

A similar problem with books: I would check them out of the library and return them unread. And my to-be-read pile of owned books just was getting bigger.

What worked for me was to set up a reading schedule for each "new" book or magazine. Simply read through a reasonable, fixed number of pages each day, until done. Lather, rinse, repeat.

I'm currently implementing this scheme by generating a calendar-format schedule for each item in HTML. Example for a book I read back in 2014, Freedom™ by Daniel Suarez:

[Sample Reading
Schedule]

I (1) print the schedule from my web browser, (2) cut it out, (3) attach to a card, and (4) use the result as a bookmark for the item. And each day, I try to meet the page goal for each item.

(Not that it matters, but for magazines I staple the schedule to one of the subscription cards that invariably accompany each issue. For books, I tape it to one of the plastic advertising cards the Yankee Candle company sends us, which are significantly more substantial.)

Now I'm not psycho about this: it's OK to get ahead of the goals if the material is compelling and I have the time. It's also OK to fall behind if there's just too much other stuff going on. (However, in my experience, just knowing that I've "fallen behind" is just enough self-nudging motivation to carve out some extra time to catch up later.)

Enough for the mechanics, on to the code. For a long time I ran a Perl script from a Linux command line to generate a schedule. But I realized that it would be (slightly) more flexible to set up an HTML form to get the schedule parameters, calling a CGI backend to display the result.

The form I'm using is here. (Do I have to mention that you can use your browser's source-viewing capabilities to view the HTML source? Nah, probably not.) What it looks like:

[Reading
Schedule Generator Form]

The only remotely interesting thing is use of the Javascript jQuery UI datepicker widget for getting the schedule's start and end dates. I didn't know nothin' about jQuery before I did this. (And I only know slightly more now; if you examine the source code for the form, it's not very complicated.)

The form also uses a CSS stylesheet found here; I originally wrote it to make the documentation I wrote at UNH look better, and it has a lot of cruft. Feel free to steal and clean it up.

So you fill out the form, for example:

[Reading
Schedule Generator Form]

… hit the submit button and the resulting page should produce the appropriate schedule. (I'm pretty sure it would work for you if you want to try it.)

The real work is performed by the Perl CGI script, which relies heavily on the smarts contained in the CGI.pm, HTML::Template, and Date::Manip modules. If you'd like to look at that (feel free to adapt it to your own preferences if you are so inclined): the plaintext Perl file is here and the html-prettyprinted version is here. The HTML template used by the script is also important and that's here.

Additional notes (October 2017).

  • As previously mentioned, the original version of the CGI script lived on the UNH "pubpages" webserver, where I enjoyed root access. It's now on the Pun Salad server, where I don't. This is problematic when you need to install some random CPAN perl module.

    Solution (or, at least, what I'm doing): use cpanm to install necessary modules "unprivileged" and put use local::lib; in scripts to find them. (This seems to work for CGIs, surprisingly.)

  • The most recent bug squashed was one I've struggled with for years: if your timezone does DST, not all days are 24 hours: the "spring forward" day has only 23; the "fall back" day has 25. This resulted in strange behavior when a reading schedule traversed one of those days.

    The fix turned out to be relatively easy: tell the script to pretend it's in the UTC timezone. Duh. That's accomplished by (for example) the line

    $startdate->config( 'setdate', 'now,UTC' );


Last Modified 2017-10-13 7:58 PM EDT