Hacking The Guild Calendar

The Guild, which is home to the Reinventorium, is also home to a black-box theatre, a theatre that happens to be located less than an arm’s length through the wall in front of my desk where I type.

This theatre plays host to a rollicking schedule of productions over the summer months, and while I’m generally happy to have my work happen in a space that oozes creativity, sometimes that oozing interferes with the quiet contemplation needed to do complex digital work.

All of which is to say: sometimes it’s hard to get work done when a troupe of fresh-faced triple threats is belting out Anne of Green Gables-themed show tunes in the room next door.

So the question then becomes: when is this happening?

The snappy new Guild website has a helpful calendar right on the front page, but the schedule information there isn’t much use to me if I’m not making a daily visit to the website: I want the information on the same day-to-day calendar that I used to manage everything else in my life, a calendar that appears on my laptop, my iPad and my phone and automatically syncs among the three.

So the question becomes: how to liberate the calendar information of of its website prison and into a shareable object?

This turned out not to be too difficult; here’s how I did it.

Look under the Hood

Firebug is a very useful tool for looking under the hood of a website: it’s like a super-charged version of “View Source.” Using Firebug’s “Network” tab, I watched as the The Guild website loaded:

The Guild website loads as I watch in Firebug's Network tab.

I noticed that one of the things to happen as an HTTP POST to a script called admin-ajax.php with the following parameters:

action=get_events
readonly=true
categories=0
excluded=0
start=1406430000
end=1410058800

The important bits here appeared to be the start and end, which were unixtime values for July 25, 2014 and September 7, 2014 respectively, which is that range of dates on this month’s calendar.

The response from this POST was a JSON-encoded array with the events taking place between these start and end dates, like this:

[
  {
    "id": "10",
    "title": "Anne & Gilbert, The Musical",
    "start": "2014-07-29 13:30:00",
    "end": "2014-07-29 15:30:00",
    "allDay": "",
    "className": "cat4 aec-repeating",
    "editable": "",
    "repeat_i": "1",
    "repeat_f": "1",
    "repeat_e": "2014-10-11"
  },
  {
    "id": "10",
    "title": "Anne & Gilbert, The Musical",
    "start": "2014-08-05 13:30:00",
    "end": "2014-08-05 15:30:00",
    "allDay": "",
    "className": "cat4 aec-repeating",
    "editable": "",
    "repeat_i": "1",
    "repeat_f": "1",
    "repeat_e": "2014-10-11"
  },

The important bits of information here were the title, the start and end date, and the “cat” in the “className” element. The “cat” was important because the calendar lists both theatre shows and art gallery shows, and I only want the theatre shows on my calendar, so I want to exclude any event with “cat1”.

Converting JSON to iCalendar

The iCalendar format is a simple, well-documented plain text format for representings events; it’s the lingua franca of calendaring apps, and you can import iCalendar files into Apple’s Calendar, into Google Calendar, and into most anything else that reads and writes event data.

To convert the JSON-encoded calendar data on The Guild website into an iCalendar-format file, I wrote a little PHP script called harvest-guild-calendar.php that uses cURL to issue the HTTP POST to The Guild website, requesting events for the next 90 days, and then parses the response and outputs each event – minus gallery shows – into a iCalendar file.

The resulting file (here’s a full snapshot taken today) looks, in part, like this:

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Reinvented Inc.\, //TheGuild 1.1//EN
X-WR-CALNAME;VALUE=TEXT:The Guild Theatre
X-WR-TIMEZONE;VALUE=TEXT:Canada/Atlantic
VERSION:2.0
BEGIN:VEVENT
SUMMARY:Anne & Gilbert, The Musical
DTSTART;TZID=Canada/Atlantic:20140805T133000
DTEND;TZID=Canada/Atlantic:20140805T153000
END:VEVENT
BEGIN:VEVENT
SUMMARY:Anne & Gilbert, The Musical
DTSTART;TZID=Canada/Atlantic:20140812T133000
DTEND;TZID=Canada/Atlantic:20140812T153000
END:VEVENT
BEGIN:VEVENT
SUMMARY:Anne & Gilbert, The Musical
DTSTART;TZID=Canada/Atlantic:20140819T133000
DTEND;TZID=Canada/Atlantic:20140819T153000
END:VEVENT

Spreading the Calendar

With the iCalendar file in hand, it was short work to create a shareable Google Calendar for The Guild, and to make this available in several formats:

  • iCalendar (suitable for importing or subscribing to in Apple’s Calendar for OS X or iOS, etc.)
  • XML (suitable for viewing in feed readers)
  • HTML (standalone viewing in a browser, or embedding in another website)

Using the Calendar

In my case, I took the iCalendar-format file and imported it into my ownCloud calendar, which then automatically echoed it the Calendar on my desktop:

And the calendar on my Android phone:

And to everywhere else I see my calendar.

As a result of all this, I have continuous awareness of when Anne & Gilbert are about to break out into song.

Like – as you can see from my phone above – in about 35 minutes from now.

Time for lunch.