Exam to iCal

Exam timetable to .ics for easy import

About

This is a very basic script for converting a paste of your exam timetable (from my.manchester.ac.uk) into a .ics file to import into your favourite calendar application.

It should work with anyone using the latest version of Blackboard to manage their exams, but was developed for Manchester University!

If you notice any bugs or problems, please report them asap! My contact details are on my personal site.

Use It

Simply paste your exam timetable from the portal below

Note: Do not copy the top line!

Data:


E.g. I paste in:

BMAN10621BT	Fundamentals of Financial Reporting	16-Jan-12	Location 1	0	9:45 AM	12:25 PM
COMP23420T	Software Engineering	18-Jan-12	Location 2	0	9:45 AM	11:30 AM
etc…

Source

Interested in how this works or want to develop something similar with PHP, you can see the (hacked together) source below:

<?php

date_default_timezone_set
("Europe/London");

function 
truncate ($string$max 50$rep '') {
    
$leave $max strlen ($rep);
    return 
substr_replace($string$rep$leave);


if(!empty(
$_POST)) {

  
header('Content-type: text/calendar; charset=utf-8');
  
header('Content-Disposition: inline; filename=calendar.ics');

  print(
"BEGIN:VCALENDAR\r\n");
  print(
"VERSION:2.0\r\n");
  print(
"PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n");
  print(
"UID:" md5(uniqid(mt_rand(), true)) . "@PezCuckow.test\r\n");

  
//$file = fopen("php://stdin",'r');
  
$string $_POST['data'];
  
//while(!feof($file)) { 
  
foreach(preg_split("/(\r?\n)/"$string) as $row){

    
//$row = fgets($file);
    
$data explode("\t"$row);

    
//Exam Code    Title    Date    Location    Seat    Start    Finish
    
if(empty($data)||empty($data[6])||$data[0]=="Exam Code") continue;

    
$start strtotime($data[2]." ".$data[5]);
    
$end strtotime($data[2]." ".$data[6]);

    
/*echo date("r", $start);
    echo date("r", $end);*/

    
print("BEGIN:VEVENT\r\n");
    print(
"DTSTART:".date("Ymd"$start)."T".date("His"$start)."\r\n");
    print(
"DTEND:".date("Ymd"$end)."T".date("His"$end)."\r\n");
    print(
"SUMMARY:".truncate($data[1], 22'...')." (".$data[0].")\r\n");
    print(
"DESCRIPTION:Title: \t".$data[1]
                        .
"\\nCode: \t".$data[0]
                        .
"\\nSeat: \t".$data[4]
                        .
"\\nStart: \t".$data[5]
                        .
"\\nEnd: \t".$data[6]
                        .
"\\n\\nRaw\\n".$row."\r\n");
    print(
"LOCATION:".$data[3]."\r\n");
    print(
"END:VEVENT\r\n");

  }
  
fclose($file);

  print(
"END:VCALENDAR\r\n");

  exit;

} else {
  include(
"examiCal/template.php");
}

?>

If you have any comments (constructive), bugs or questions please contact me on the details provided at my homepage (top right).

Thanks

Thanks for using this script, I hope you found it of use!

If you have any comments (constructive or otherwise), bugs or questions please contact me on the details provided at my homepage (top right).

Actually while you're here why don't you visit my website, and learn more about me, do you even know who I am?

If you're feeling particularly thankful you could put towards my next cup to tea!

Terms of Use: By using this you agree to buy Pez a drink :-)