HowTo: Consume Google Calendars with Perl

Our youth group uses a Google Calendar to schedule upcoming events. Although the information will be updated throughout the year, we wanted to give parents an overview sheet that lists the events we’ve scheduled already.

Rather than creating an event list by hand, I wrote some Perl to consume Google’s calendar data source and format it with HTML and CSS. This is pretty rough code, hacked together in a few hours to accomplish my specific purpose without much consideration for code reuse or consumption by the public. Nevertheless, I’m sure I’m not the only one who’s interested in doing this.

The first Perl script creates an agenda view that lists each event’s start date and title on a line by itself. Slight modifications to the HTML will allow you to split the events into two columns. Source code and sample output can be found here.

The second Perl script creates a yearly calendar view and associates each event’s day with a CSS class that matches the event’s title. There’s work required in the stylesheet to style events individually, since you may want events with various titles to have the same visual appearance. This script works best if you have many repeating events in the calendar. Source code and sample output is here.

Before you use the Perl scripts, you’ll need to install the HTTP::Date and Date::Calc modules from CPAN. On Mac OS X, you’ll do this by opening Terminal.app and typing “sudo cpan”, then “install HTTP::Date” and “install Date::Calc”.

You’ll also need to crack open the Perl script and set $calendarXmlUrl to the appropriate Google Calendar data URL for your calendar. Take a close look at the URL that’s in the script already for what options need to be set.

Good luck! I hope this is a useful starting place for someone.

Update: I’ve also added a script which produces monthly calendars… you can find it here.

Update 2: The monthly calendar script now produces both half-page and full-page calendars.

2 Comments

  1. Dennis
    Posted September 15, 2009 at 8:29 pm | Permalink | Reply

    Love your applescripts and perl scripts.. I’d love to use your google calendar consuming script to automatically build a webpage listing my schedule. I’ve successfully synced my google public calendar with a calender I can update within iCal. Now I just need to call the perl script from an html file I’ll post on my webpage. I think I can upload the perl script to my webhost but don’t know how to call it from the html page to get it’s data. Any ideas?

    Thanks again!

  2. Posted September 17, 2009 at 6:59 pm | Permalink | Reply

    Hi Dennis,

    Does your hosting company support CGI scripts? That might be a way to do this… unfortunately I live in the ASP.NET world so don’t know too much about how that would look.

    Alternatively, what if you set up a cron job that runs the perl script every night and spits out an .html file for your web server to consume?

One Trackback

  1. [...] Perl and XHTML/CSS to produce documents destined for print. This has served me well when creating calendars, for example — so when it came time for me to generate a directory for our youth group, I [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*