Import Events into Google Calendar

This is a wrapper class for some Google calendar import methods. Frequently I get a list with lots of dates I’ve to add to the Google calendar. To bad that there is no calendar import function for the Google calendar. But fortunately, Zend provides a nice PHP framework for this task. Let’s have a look how to add calendar events by using this framework:

Requirements

My wrapper uses parts of the Zend framework. If you use gentoo just let portage do that task: emerge -av dev-php5/ZendFramework.
I’m sure that other distributions also maintain packages for that framework. If not, you’ve to install the Zend Framework by hand like desribed here.

You need at least a running PHP interpreter (here: dev-lang/php-5.2.10).

Parsing Data

Before we create an event, we’ve to organize data. This is done by creating corresponding objects:

$Match = new Match();
$Match->Number = 4265;
$Match->Location = "Hagwaldhalle Pfinztal, Ortsteil Kleinsteinbach";
$Match->Team = "VSG Kleinsteinbach";
$Match->Opponent = "TuS KA/Rüppurr II";
$Match->Date = new DateTime("06.03.2010 15:00");

Note, that you can use the static method Match::Parse($Path) in order to parse a data resource (given by $Path) with the following format:

4201 TuS Durmersheim III - TV Liedolsheim        03.10.2009 (15:00) Gymnasiumshalle Durmersheim
4202 TuS Durmersheim III - VSG Kleinsteinbach
4203 SG Hilpertsau/Au - TSV Ubstadt              03.10.2009 (15:00) Ebersteinhalle Obertsrot
4204 SG Hilpertsau/Au - SC Wettersbach

You can find a sample data file here.

Importing Data

Last step is to import the objects to your Google calendar. Check your Google calendar settings in order to get your private calendar ID (must be somewhat with @group.calendar.google.com as prefix).

Now, we have to login to the Google service. This can be done by Match::Login($Username,$Password). This method might throw exceptions on failures, so make sure you catch them in an appropriate way.

Finally you can create a calendar entry from a Match object by Match->Create($Feed). Where $Feed is the URL to your private Google calendar: http://www.google.com/calendar/feeds/ID@group.calendar.google.com/private/full.

Source & Example

You can checkout the latest version from Google code:
svn checkout http://matchimport.googlecode.com/svn/trunk/ matchimport-read-only.
There’s an example script run.php which contains the basic steps to import a Match schedule.

By default, the duration of a match is set to 100 mins and there’s a 20 min break between two matches. Further, a reminder is set which reminds the Google calendar user by SMS two days before the match starts.

The source is under Free BDS license, so feel free to modify the code.
Visit the Google code project for more details.

This entry was posted in Volleyball, Web Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>