Automatically synch Technikum Wien schedule (LV-Plan) with Google Calendar

edit: the code has been adjusted to present a personalized caledar to the user.

At my university, there is a schedule for all the lectures available. In different formats, from plain html over csv onto iCal, both version 1 and 2 are supported. Great. The only issue here: one can only access that calendar AFTER logging into the CIS (Campus Information System). So, I could not simply import the iCal into my Google Calendar as I’d need to authenticate each and every time.

As there are changes to the schedule over and over again, it would be quite inconvenient to manually download the iCal file and re-import it into Google Calendar over and over again. I knew that I’d forget to do so one day and I might show up at the university just to find out that the lecture had been canceled. Or even worse – the other way around.

My idea was as follows:

I’d use a php script in order to download the iCal file for me. Fortunately, there is cURL which would allow me to fetch the calendar. And php could then just echo back the result, which would be importable into – right, Google Calendar.

calendarRequest

The basic php code is pretty simple, and there is a vast amount of tutorials available on the net. That’s what I came up after several minutes:


<?php
$user="myuser";
$password="password";

$url = 'https://cis.technikum-wien.at/cis/private/lvplan/stpl_kalender.php?type=student&stg_kz=302&format=ical&version=2&target=ical';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_USERPWD, "{$user}:{$password}");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   // no verify
$data = curl_exec($curl);
curl_close($curl);

echo $data;

?>

However, there was a slight security problem: if my Apache would have been misconfigured for any reason, it might not execute the php file. Even worse: someone may download that file and read my username and password. Something I definitely would not appreciate. So, the next step was to exclude the credentials and secure them.

I would exclude the credentials into an external php config file and secure this file using .htaccess:

calendarRequest-secure

The config.inc.php file would contain just two variables: my username and password.


<?php
$config['usr'] = 'user';
$config['pwd'] = 'password';
?>

My .htaccess file would tell Apache to prevent visitors from accessing that configuration file:


<files config.inc.php>
order allow,deny
deny from all
</files>

Finally, I had to update my php script which would fetch the calendar:


<?php
include_once('config.inc.php');

$student = htmlspecialchars($_GET["student"]);

$url = "http://cis.technikum-wien.at/cis/private/lvplan/stpl_kalender.php?type=student&pers_uid={$student}&format=ical&version=2&target=ical";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_USERPWD, "{$config['usr']}:{$config['pwd']}");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   // no verify
$data = curl_exec($curl);
curl_close($curl);

echo $data;

?>

 

The final result can be seen here (you can of course alter the student id for your personal calendar):

Of course, this would just return the business informatics calendar for the master studies. Adjusting the url however should be quite simple. The last step was to provide my Google Calendar with that URL – which worked like a charm. Google would refresh those calendars every few hours which would be fine with my use case.

By the way: there’s also an App for Android available (not from me) which offers basically the same functionality, however you would not need a webserver 😉