Last active
August 29, 2015 14:05
-
-
Save tkon99/35cee5a723d08f7ccb63 to your computer and use it in GitHub Desktop.
Rooster Parser for Gepro Osi (school 507) with changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//note: this uses an external dom library | |
include('simple_html_dom.php'); | |
$dag = $_GET["d"]; | |
$l = $_GET["l"]; | |
$r = $_GET["r"]; | |
if(empty($dag) || empty($l) || empty($r)){ | |
return; | |
}else{ | |
if($dag == "1"){ | |
$dag = '{"maandag":['; | |
$count = 0; | |
}else if($dag == "2"){ | |
$dag = '{"dinsdag":['; | |
$count = 1; | |
}else if($dag == "3"){ | |
$dag = '{"woensdag":['; | |
$count = 2; | |
}else if($dag == "4"){ | |
$dag = '{"donderdag":['; | |
$count = 3; | |
}else if($dag == "5"){ | |
$dag = '{"vrijdag":['; | |
$count = 4; | |
}else{ | |
$dag = '{"maandag":['; | |
$count = 1; | |
} | |
} | |
$l = urlencode($l); | |
$r = urlencode($r); | |
$url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?leerling='.$l.'&type=Leerlingrooster&afdeling='.$r.'&wijzigingen=1&school=507'; | |
//$url = 'http://roosters5.gepro-osi.nl/roosters/rooster.php?klassen%5B%5D=nH3a&type=Klasrooster&wijzigingen=1&school=507'; | |
//werkt blijkbaar ook voor klassen :P | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Googlebot/2.1 (http://www.googlebot.com/bot.html)"); | |
curl_setopt($ch, CURLOPT_URL,$url); | |
curl_setopt($ch, CURLOPT_FAILONERROR, true); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
$html = curl_exec($ch); | |
$dom = str_get_html($html); | |
$roostertable = $dom->find('tr td[class=tableCell] table'); | |
$af = ']}'; | |
$counter = 0; | |
for($i = $count; $i<50; $i=$i+5){ | |
$counter++; | |
$uurnummer = ($i/5)+1; | |
$uurnummer = floor($uurnummer); | |
$uur = $roostertable[$i]; | |
$data = $uur->find('tr td'); | |
$leraar = $data[0]; | |
$lokaal = $data[2]; | |
$vak = $data[4]; | |
$cluster = $data[5]; | |
$class = $leraar->class; | |
if($class == 'tableCellNew'){ | |
$status = 'wijziging'; | |
}else if($class == 'tableCellRemoved'){ | |
$status = 'uitval'; | |
}else{ | |
$status = 'normaal'; | |
} | |
if($counter !== 10){ | |
$dag .= '{"'.$uurnummer.'":[{"status":"'.$status.'","leraar":"'.$leraar.'","lokaal":"'.$lokaal.'","vak":"'.$vak.'","cluster":"'.$cluster.'"}]},'; | |
}else{ | |
$dag .= '{"'.$uurnummer.'":[{"status":"'.$status.'","leraar":"'.$leraar.'","lokaal":"'.$lokaal.'","vak":"'.$vak.'","cluster":"'.$cluster.'"}]}'; | |
$dag .= $af; | |
} | |
} | |
echo $dag; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment