March 19, 2010 at 8:25 PM by Dr. Drang
Ear infections and an asthma flareup have hit the Drang haus and we now have a pile of medicine to dose our boys with—so much, my wife asked me to make up a calendar so we could keep track of it all. I turned to Pcal, Python, and TextMate to whip one up quickly.
What I came up with is basically a to-do list in calendar form. It had to be on paper, because it was going to be used in our kitchen, the household dispensary and overall command center. That meant Pcal, the PostScript calendar creation utility that I’ve blogged about before. In addition to empty calendars of many different formats, Pcal can also use a date file to generate calendars with entries.
As Pcal’s man page shows, the date file format is absurdly flexible, but the most basic entries will look like this
3/25/10 pick up flowers 3/30/10 party
with the date followed by the description, one entry per line. What I needed was a date file with entries like this
3/20/10 Boy1 AM pred 3/20/10 Boy1 AM amox 3/20/10 Boy2 AM amox 3/20/10 Boy1 PM pred 3/20/10 Boy1 PM amox 3/20/10 Boy2 PM amox
that went on for about ten days.
The similarity of the entries and my general laziness inspired me to come up with this little Python script:
#!/usr/bin/python for i in range(20,32): print '''3/%d/10 Boy1 AM pred 3/%d/10 Boy1 AM amox 3/%d/10 Boy2 AM amox 3/%d/10 Boy1 PM pred 3/%d/10 Boy1 PM amox 3/%d/10 Boy2 PM amox''' % (i,i,i,i,i,i)
which I typed into TextMate, selected, and then executed with TextMate’s Execute Selection Inserting Result command. The output, all 72 lines, appeared in the file below the script. I deleted the script lines and saved the date entries as
Then from the command line, I ran
pcal -S -n Helvetica/9 -f meds.txt 3 2010 1 | ps2pdf - meds.pdf
which gave me a PDF file, “meds.pdf,” that looked like this
The idea is to scratch off each medicine—amoxicillin and prednisone—as it’s given.
In the call to
-S option told Pcal not to include little calendars of the previous and next months. The
-n Helvetica/9 option told it to print the day entries in 9-point Helvetica—trial and error told me that was the biggest font I could use without the entries spilling over into the boxes below. The
-f meds.txt option told Pcal to use
meds.txt as the date file. Finally, the
3 2010 1 input told Pcal to make one month, starting in March of 2010.
Pcal’s PostScript output was then piped to
ps2pdf, which converted it into the
As with most of the little scripts I blog about, this took much longer to describe than to do. The Python script was written about as fast as I could type it. Because I don’t use Pcal that often, I spent most of my time looking through its man page for the options I wanted, and then playing with the font size until I got the entries to just fit.