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