Skip to content
Snippets Groups Projects
Commit 15538e89 authored by Hotte's avatar Hotte
Browse files

working parser TODO:Logik

parent 673bd87a
No related branches found
No related tags found
No related merge requests found
......@@ -2,30 +2,30 @@
// Universal
$SEARCH_URL = "https://www.lsf.tu-dortmund.de/qisserver/rds?state=wsearchv&search=1";
$SUBJECT_LIST_SS = array (
"Datenstrukturen, Algorithmen und Programmierung 1",
"Mathematik für Informatik II",
"Datenstrukturen, Algorithmen und Programmierung 2",
"Betriebssysteme",
"Elektrotechnik und Nachrichtentechnik",
"Softwaretechnik",
"Informationssysteme",
"Grundbegriffe der Theoretischen Informatik",
"Höhere Mathematik II (ET/IT)"
new SUBJECT("Datenstrukturen, Algorithmen und Programmierung 1","Datenstrukturen, Algorithmen und Programmierung 1","DAP 1"),
new SUBJECT("Mathematik für Informatik II","Mathematik für Informatik II","MafI 2"),
new SUBJECT("Datenstrukturen, Algorithmen und Programmierung 2","Datenstrukturen, Algorithmen und Programmierung 2","DAP 2"),
new SUBJECT("Betriebssysteme","Betriebssysteme","BS"),
new SUBJECT("Elektrotechnik und Nachrichtentechnik","Elektrotechnik und Nachrichtentechnik","EtNt"),
new SUBJECT("Softwaretechnik","Softwaretechnik","Swt"),
new SUBJECT("Informationssysteme","Informationssysteme","IS"),
new SUBJECT("Grundbegriffe der Theoretischen Informatik","Grundbegriffe der Theoretischen Informatik","GTI"),
new SUBJECT("Höhere Mathematik II (ET/IT)","Höhere Mathematik II","HöMa 2")
);
$SUBJECT_LIST_WS = array (
"Datenstrukturen, Algorithmen und Programmierung 1",
"Rechnerstrukturen",
"Mathematik für Informatik I",
"Logik für Informatiker",
"Funktionale Programmierung",
"Rechnernetze und verteilte Systeme",
"Wahrscheinlichkeitsrechnung und Mathematische Statistik für Informatiker",
"Höhere Mathematik I (ET/IT/I-I)",
"Höhere Mathematik III (P/ET/ITMP/I-I)"
new SUBJECT("Datenstrukturen, Algorithmen und Programmierung 1","Datenstrukturen, Algorithmen und Programmierung 1","DAP 1"),
new SUBJECT("Rechnerstrukturen","Rechnerstrukturen","RS"),
new SUBJECT("Mathematik für Informatik I","Mathematik für Informatik I","MafI 1"),
new SUBJECT("Logik","Logik","Logik"),
new SUBJECT("Funktionale Programmierung","Funktionale Programmierung","FuPro"),
new SUBJECT("Rechnernetze und verteilte Systeme (ehemals BSRvS 2)","Rechnernetze und verteilte Systeme","RvS"),
new SUBJECT("Wahrscheinlichkeitsrechnung und Mathematische Statistik für Informatiker","Wahrscheinlichkeitsrechnung und Mathematische Statistik","WruMS"),
new SUBJECT("Höhere Mathematik I (ET/IT/I-I)","Höhere Mathematik I","HöMa 1"),
new SUBJECT("Höhere Mathematik III (P/ET/ITMP/I-I)","Höhere Mathematik III","HöMa 3")
);
// JSON
$JSON_NAME = "../../tmp/lsfView.json";
$JSON_INC_NR = false;
$JSON_INC_SHORT = false;
$JSON_INC_NAME = true;
$JSON_INC_SHORT = true;
?>
\ No newline at end of file
......@@ -36,17 +36,17 @@ class EVENT {
}
public function toJson() {
$json = '{\n';
$json = '"Day": '.$this->day;
$json = '"StartTime": '.$this->startTime;
$json = '"EndTime": '.$this->endTime;
$json = '"Room": '.$this->room;
$json = '}\n';
$json = '{';
$json .= '"Day": '.$this->day;
$json .= ',"StartTime": "'.$this->startTime . '"';
$json .= ',"EndTime": "'.$this->endTime . '"';
$json .= ',"Room": "'.$this->room . '"';
$json .= '}';
return $json;
}
public function __toString() {
return "\nDay: " . $this->day . ", StartTime: " . $this->startTime . ", EndTime: ". $this->endTime . ", Room: ".$this->room;
return "Day: " . $this->day . ", StartTime: " . $this->startTime . ", EndTime: ". $this->endTime . ", Room: ".$this->room;
}
}
?>
\ No newline at end of file
......@@ -8,7 +8,7 @@ function booleanToString($bool) {
}
//TODO:
function toJson($subjects, $jsonName, $inc_nr = true, $inc_short = true) {
function toJson($subjects, $jsonName, $inc_name = true, $inc_short = true) {
$kommata = false;
$json = '{';
foreach ( $subjects as $subject ) {
......@@ -17,21 +17,24 @@ function toJson($subjects, $jsonName, $inc_nr = true, $inc_short = true) {
} else {
$kommata = true;
}
$json .= $subject->toJson ( $inc_nr, $inc_short);
$json .= $subject->toJson ( $inc_name, $inc_short);
}
$json .= "}";
file_put_contents ( $jsonName, $json );
file_put_contents ( $jsonName , $json );
}
function parsSubject($html,$subjectName) {
$subject = new SUBJECT($subjectName);
$subject->setNr($html->find('td',2)->innertext);
$subject->setShort($html->find('td',3)->innertext);
function parsSubject($html,$subject) {
echo "Parsing " . $subject->getSearchName() . "\n";
//$subject->setNr($html->find('td',2)->innertext);
//$subject->setShort($html->find('td',3)->innertext);
$html = $html->find('table[summary="Übersicht über alle Veranstaltungstermine"]',0);
$html = $html->find('tr');
array_shift($html);
foreach($html as $event) {
$subject->addEvent(new EVENT(fixDay($event->children()[1]->innertext),fixTimeStart($event->children()[2]->innertext),fixTimeEnd($event->children()[2]->innertext),$event->children()[5]->first_child()->innertext));
if(count($html)!=0){
echo " - Events: " . count($html) . "\n";
foreach($html as $event) {
$subject->addEvent(new EVENT(fixDay($event->children()[1]->innertext),fixTimeStart($event->children()[2]->innertext),fixTimeEnd($event->children()[2]->innertext),$event->children()[5]->first_child()->innertext));
}
}
return $subject;
}
......@@ -68,18 +71,22 @@ function fixDay($day){
}
function fixTimeStart($time){
$time = str_replace(' ',"",$time);
$time = str_replace(' ',"",$time);
$time= removeSpace($time);
$time = html_entity_decode($time);
$time = substr ( $time , 0 , 5 );
return $time;
}
function fixTimeEnd($time){
$time = str_replace(' ',"",$time);
$time = str_replace(' ',"",$time);
$time= removeSpace($time);
$time = html_entity_decode($time);
$time = substr ( $time , 12 , 15);
return $time;
}
function removeSpace($text){
$text = str_replace(' ',"",$text);
$text = str_replace(' ',"",$text);
return $text;
}
?>
\ No newline at end of file
......@@ -2,11 +2,11 @@
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require 'config.php';
require 'simple_html_dom.php';
require 'subject.php';
require 'event.php';
require 'helper.php';
require 'config.php';
// check semester
switch (date("n")) {
......@@ -60,29 +60,34 @@ if($SEMESTER == 1){
// search subject
$subjects = array ();
foreach ( $SUBJECT_LIST as $SUBJECT ) {
$html = file_get_html ( $SEARCH_URL."&veranstaltung.dtxt=".str_replace(' ',"+",$SUBJECT)."&veranstaltung.semester=".date("Y").$SEMESTER);
echo "Searching ".$SUBJECT->getSearchName()."-";
$html = file_get_html ( $SEARCH_URL."&veranstaltung.dtxt=".str_replace(' ',"+",$SUBJECT->getSearchName())."&veranstaltung.semester=".date("Y").$SEMESTER);
if ($html != null) {
$html = $html->find('a[title="Mehr Informationen zu '.$SUBJECT.'"]',0);
if ($html != null) {
$HREF = $html->href;
$html->clear();
unset($html);
$html = file_get_html ( html_entity_decode($HREF) );
if ($html != null) {
array_push ( $subjects, parsSubject ($html,$SUBJECT) );
} else {
echo "\"".$SUBJECT."\"-Site nicht aufrufbar\n";
$list = $html->find('a[title="Mehr Informationen zu '.$SUBJECT->getSearchName().'"]');
if (count($list) != 0) {
foreach($list as $a){
if(removeSpace($a->parent()->parent()->children (2)->innertext) == "Vorlesung") {
echo "Hit-";
$HREF = $a->href;
$html->clear();
unset($html);
$html = file_get_html ( html_entity_decode($HREF) );
if ($html != null) {
array_push ( $subjects, parsSubject ($html,$SUBJECT) );
} else {
echo "\"".$SUBJECT->getSearchName()."\"-Site nicht aufrufbar\n";
}
break;
}
}
} else {
echo "\"".$SUBJECT."\"-Search liefert kein passendes Ergebnis\n";
}
} else {
echo "\"".$SUBJECT."\"-Search nicht aufrufbar.\n";
echo "\"".$SUBJECT->getSearchName()."\"-Search liefert kein passendes Ergebnis\n";
}
} else {
echo "\"".$SUBJECT->getSearchName()."\"-Search nicht aufrufbar.\n";
}
}
echo $subjects[1].toJson();
toJson ( $subjects, $JSON_NAME, $JSON_INC_NR, $JSON_INC_SHORT);
toJson ( $subjects, $JSON_NAME, $JSON_INC_NAME, $JSON_INC_SHORT);
?>
\ No newline at end of file
<?php
class SUBJECT {
private $searchName = "";
private $name = "";
private $nr = 0;
private $short = "";
private $events = array ();
function __construct($name) {
function __construct($searchName = "", $name, $short = "") {
$this->searchName = $searchName;
$this->name = $name;
$this->short = $short;
}
public function getSearchName() {
return $this->searchName;
}
public function getName() {
return $this->name;
}
public function getNr() {
return $this->nr;
}
public function getShort() {
return $this->short;
}
public function getEvents() {
return $this->events;
}
public function setSearchName($searchName) {
$this->searchName = $searchName;
}
public function setName($name) {
$this->name = $name;
}
public function setNr($nr) {
$this->nr = $nr;
}
public function setShort($short) {
$this->short = $short;
}
......@@ -38,11 +40,15 @@ class SUBJECT {
}
//TODO
public function toJson($inc_nr = true, $inc_short = true) {
public function toJson($inc_name = true, $inc_short = true) {
$kommata = false;
$json = '"Name": '. $this->name;
$json = '"Nr": '. $this->nr;
$json = '"Short": '. $this->short;
$json = '';
if($inc_name){
$json = '"Name": "'. $this->name . '", ';
}
if($inc_short){
$json .= '"Short": "'. $this->short . '", ';
}
$json .= '"Events": [';
foreach ( $this->events as $event ) {
if ($kommata) {
......@@ -56,11 +62,13 @@ class SUBJECT {
return $json;
}
public function __toString() {
$string = "\nName: " . $this->name . ", Nr: " . $this->nr . ", Short: ".$this->short. ", Events: ";
$string = "Name: " . $this->name;
$string .= ", Short: ".$this->short;
$string .= ", Events: ";
foreach ( $this->events as $event ) {
$string .= $event;
}
return $string."\n";
return $string;
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment