aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFinn Behrens <me@kloenk.de>2020-11-15 22:13:30 +0100
committerFinn Behrens <me@kloenk.de>2020-11-15 22:13:30 +0100
commit49df4a01529ffb41228bd76d8c4fbce4f8bdedf9 (patch)
tree3ee28faa2c5fdce959ffcf6a55a89876d964efa1
parent411fd3c067235a7a2b0ae6668970e003e82ce146 (diff)
downloadbackend-49df4a01529ffb41228bd76d8c4fbce4f8bdedf9.tar.gz
backend-49df4a01529ffb41228bd76d8c4fbce4f8bdedf9.tar.xz
backend-49df4a01529ffb41228bd76d8c4fbce4f8bdedf9.zip
WIP: create slp parsermain
-rw-r--r--src/dsb/mod.rs4
-rw-r--r--src/error.rs4
-rw-r--r--src/lib.rs4
-rw-r--r--src/slp/behrens_slp.html387
-rw-r--r--src/slp/html.rs139
-rw-r--r--src/slp/mod.rs41
6 files changed, 577 insertions, 2 deletions
diff --git a/src/dsb/mod.rs b/src/dsb/mod.rs
index 2dbfafd..fc7d696 100644
--- a/src/dsb/mod.rs
+++ b/src/dsb/mod.rs
@@ -77,11 +77,11 @@ mod test {
#[test]
fn read_dsb() {
let html = std::fs::read_to_string("./src/dsb/dsb.html").unwrap();
- println!("{}", html);
let dsb = DSB::parse(&html).unwrap();
assert_eq!(dsb.len(), 3);
- println!("{:?}", dsb);
+ //println!("{:?}", dsb);
+ // TODO: more asserts
}
}
diff --git a/src/error.rs b/src/error.rs
index 7092b01..691a915 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -9,6 +9,8 @@ pub enum Error {
InvalidCourse(String),
InvalidTrack(String),
+ SlpParse(String),
+
ChronoParse(chrono::ParseError),
ParseInt(std::num::ParseIntError),
@@ -29,6 +31,8 @@ impl fmt::Display for Error {
use Error::*;
match self {
DsbParse(v) => write!(f, "Failed to parse dsb: {}", v),
+ SlpParse(v) => write!(f, "Failed to parse slp: {}", v),
+
InvalidWeek(v) => write!(f, "Week '{}' is invalid", v),
InvalidHour(v) => write!(f, "Hour '{}' is invalid", v),
InvalidRoom(v) => write!(f, "Room '{}' is invalid", v),
diff --git a/src/lib.rs b/src/lib.rs
index 9bcba6a..f966594 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,9 @@
+/// DSB scrapers and helper functions
pub mod dsb;
+/// SLP scrapers and helper functions
+pub mod slp;
+
pub mod types;
pub(crate) mod error;
diff --git a/src/slp/behrens_slp.html b/src/slp/behrens_slp.html
new file mode 100644
index 0000000..a5cc3ad
--- /dev/null
+++ b/src/slp/behrens_slp.html
@@ -0,0 +1,387 @@
+<!doctype html>
+<html lang="de">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>SLP-PlanInfo | Anzeige</title>
+ <meta name="author" content="Michael Ziemke, Koeln">
+ <meta name="keywords" content="PlanInfo Stundenplan Anzeige anzeigen Auskunft PHP Untis SchILD Kurs">
+ <link rel="stylesheet" href="planinfo.css" type="text/css">
+ <link rel="stylesheet" href="/html/css/navi.css.php" type="text/css">
+ <link rel="icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" href="favicon.png" type="image/png" sizes="192x192">
+ </head>
+ <body class="anzeige">
+<!-- ENDE Teil 1 HTML -->
+
+
+ <script type="text/javascript" language="JavaScript">
+ <!--
+ if( !navigator.cookieEnabled ) {
+ info = "Cookies sollten erlaubt sein,\nansonsten wird für den nächsten Besuch\ndie Schulauswahl nicht gespeichert.";
+ } else {
+ if( navigator.cookieEnabled ) {
+ info = "";
+ // ok
+ } else {
+ info = "Die Cookie-Einstellung des Browsers ist nicht feststellbar.\nBitte überprüfen Sie selbst,\ndass Cookies erlaubt sind (empfohlen).";
+ }
+ }
+// alert(navigator.userAgent.search(/Firefox\/5.0/));
+ if( !navigator.javaEnabled() ) {
+ // ACHTUNG: In Firefox 5.0.x liefert navigator.javaEnabled() ein falsches Ergebnis!
+ //if (navigator.userAgent.search(/Firefox\/5.0/) < 0) {
+ obj = navigator.userAgent;
+ if (obj.indexOf("Firefox/5") * (obj.indexOf("Firefox/6") == 1)) {
+ // KEIN Browser Mozilla Firefox 5 oder 6; dort wird .javaEnabled() falsch behandelt
+ if (info != "") info += "\n\n";
+ info += "JavaScript ist im Browser abgeschaltet,\nmuss für die Nutzung von PlanInfo aber erlaubt sein!";
+ info += "\n\nHinweis: Im Browser Firefox 5.x / 6.x\nwird diese Info ggf. irrtümlich gezeigt.";
+ info += "\nPrüfen Sie dort unter Extras / Einstellungen / Inhalt,\nob [JavaScript aktivieren] markiert ist.";
+ }
+ }
+ if (info != "") alert (info);
+ -->
+ </script>
+ <noscript>
+ <h3 style="color:red;">JavaScript ist im Browser abgeschaltet,
+ sollte für die Nutzung von PlanInfo aber erlaubt sein!</h3>
+ </noscript>
+
+ <input type="checkbox" id="hamburg">
+ <label for="hamburg" class="hamburg">
+ <span class="line"></span>
+ <span class="line"></span>
+
+ <span class="line"></span>
+ </label>
+ <nav class="navi">
+ <ul class="navi navi1">
+ <input class="withsub" type="checkbox" id="slp-module" /><label for="slp-module" title="Klick öffnet das Modul-Menü" class="navi"><img class="navi" src="/html/favicon.ico" /> SLP-Module &raquo;</label><ul class="navi navi2"><li class="navi" title="SLP-Modul-Auswahl" ><a class="navi" href="/html?ug=lev-llg" target="slp" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/favicon.ico" /> Start / Home</a></li><li class="navi" title="Alumni - das Ehemaligen-Portal" ><a class="navi" href="/html/alumni?ug=lev-llg" target="alumni" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/alumni/favicon.ico" /> Alumni</a></li><li class="navi" title="Intern-Portal informiert Lehrer exklusiv" ><a class="navi" href="/html/intern?ug=lev-llg" target="intern" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/intern/favicon.ico" /> Intern</a></li><li class="navi" title="PlanInfo gibt Stundenplan-Auskunft" ><a class="navi" href="/html/planinfo?ug=lev-llg" target="planinfo" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/planinfo/favicon.ico" /> PlanInfo</a></li><li class="navi" title="Termin-Portal sorgt für Übersicht" ><a class="navi" href="/html/termin?ug=lev-llg" target="termin" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/termin/favicon.ico" /> Termin</a></li><li class="navi" title="UpDown bietet Zusatz-Lernmittel" ><a class="navi" href="/html/updown?ug=lev-llg" target="updown" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" ><img class="navi" src="/html/updown/favicon.ico" /> UpDown</a></li></ul><hr class="navi" /><li class="navi" title="Zur Schul-Website" ><a class="navi" href="http://landrat-lucas.org" target="Planinfo2" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Schul-Website</a></li><hr class="navi" /><li class="navi" title="Option ist noch nicht implementiert!" ><a class="navi" href="./planinfo_start.php?ug=lev-llg&action=search" target="_self" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Schnellsuche</a></li><li class="navi" title="Option ist noch nicht implementiert!" ><a class="navi" href="./planinfo_start.php?ug=lev-llg&action=choosePlan" target="_self" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Planart-Wahl</a></li><li class="navi" title="Option ist noch nicht implementiert!" ><a class="navi" href="./planinfo_start.php?ug=lev-llg&action=chooseWeek" target="_self" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Woche-Wahl</a></li><input class="withsub" type="checkbox" id="service" /><label for="service" class="navi">Service &raquo;</label><ul class="navi navi2"><li class="navi" title="Option ist noch nicht implementiert!" ><a class="navi" href="./planinfo_start.php?ug=lev-llg&action=print" target="_self" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Drucken</a></li></ul><li class="navi" title="Abmelden aus dem Modul PlanInfo" ><a class="navi" href="./planinfo_login.inc.php?logout=1" target="_self" onClick="document.getElementById(&quot;hamburg&quot;).checked = false;" >Logout</a></li>
+ </ul>
+ </nav>
+
+ <!-- Beginn Titel und Abfrage responsive -->
+ <div class="onlyprint">
+ <h3>Landrat-Lucas-Gymnasium, Leverkusen</h3>
+ <h3> | 1. Halbjahr 2020/21
+ </h3>
+ </div>
+ <div class="row noprint">
+ <div class="col-6 col-m-6">
+ <h3 style="margin-left: 1.5em; ">Landrat-Lucas-Gymnasium, Leverkusen</h3>
+ </div>
+ <div class="col-6 col-m-6">
+ <h3>1. Halbjahr 2020/21
+ <span class="plan2"> | Stand: 12.11.2020</span>
+ </h3>
+ </div>
+ </div>
+ <div class="row noprint">
+ <div class="colmob-70 col-10 col-m-10">
+ <p class="plan2">SO, 15.11.2020 | KW 46 | A-Woche</p>
+ <p class="plan2"></p>
+ <p class="plan2" onClick="window.open(&quot;planinfo_chart.php?ug=lev-llg&quot;, &quot;SLP-Chart&quot;);" title="Besucher-Statistik seit August 2015 - Links-Klick zeigt 31-Tage-Statistik-Diagramm">Sie sind Besucher Nr. 974.978&nbsp;<img src="./images/chart_big.png" style="height:1.0em;"></p>
+ </div>
+ <div class="colmob-30 col-2 col-m-2">
+ <input type="image" class="plan plan24a" src="images/bookmark.png" value="Link" onClick="window.open(&quot;/html/planinfo/planinfo_start.php?ug=lev-llg&search=Behrens&choose=1&quot;,&quot;_self&quot;)" alt= "Link" title = "Link-Adresse für Lesezeichen-Ablage optimieren (vgl. YouTube-Tutorial)!">
+ <input type="image" class="plan plan24a" src="images/print.png" value="Print"
+ onClick="window.print();"
+ alt= "Drucken" title = "Drucken">
+ <input type="image" class="plan plan24a" src="images/out.png" value="Logout"
+ onClick="location.href='./planinfo_login.inc.php?logout=1';"
+ alt= "Logout" title = "Logout">
+ </div>
+ </div>
+
+ <!-- Beginn Abfrage responsive -->
+ <div class="row noprint">
+ <div class="col-12 col-m-12">
+ <p class="info">Bitte geben Sie eine Bezeichnung in der Schnellsuche an <b>oder</b> wählen Sie die Planart:</p>
+ </div>
+ </div>
+
+ <div class="row noprint">
+ <div class="col-4 col-m-4">
+ <p class="label">Schnellsuche:</p>
+ <form action="/html/planinfo/planinfo_start.php?ug=lev-llg" method="post" accept-charset="utf-8" style="display:inline;"><input class="plan" type="text" name="search" id="search" value="" placeholder="Kürzel, Klasse, Raum, Nachname, GO-Stufe" maxlength="30" title="Eingabe (Schüler-Nachname, Lehrer-Kürzel, Raumbezeichnung, Klasse, GO-Stufe) beenden mit [Enter] oder [OK]"><input type="hidden" name="wochewahl" value="B">&nbsp;<input class="plan plan24" type="image" src="images/ok.png" value="Start" onClick="submit();" alt= "Anzeigen" title = "Anzeigen"><input type="hidden" name="scrolling" id="scrolling" value="" /></form><input type="hidden" id="dbidx" value="1844">
+ </div>
+ <div class="col-5 col-m-5">
+ <p class="label">Planart:</p>
+ <select class="plan" name="artwahl" id="artwahl" onChange="bildeObjektWahl()" size="1"><optgroup><option selected="selected" value=" ">bitte wählen</option><option value="L">Lehrer</option><option value="K">Klasse</option><option value="R">Raum</option><option value="O">GO-Stufe</option></optgroup></select><span class="noprint">&nbsp;<input class="plan plan12" type="image" src="images/left-red-outlined.png" value="Voriger" name="scroll_prev" onClick="val=&quot;prev&quot;;document.getElementById(&quot;scrolling&quot;).value=val; zeigePlan()" alt= "Voriger" title = "Vorigen anzeigen; auch durch Pfeil-links-Taste" /><input class="plan plan12" type="image" src="images/right-green-outlined.png" value="Nächster" name="scroll_next" onClick="val=&quot;next&quot;;document.getElementById(&quot;scrolling&quot;).value=val; zeigePlan()" alt= "Nächster" title = "Nächsten anzeigen; auch durch Pfeil-rechts-Taste" /></span>
+ </div>
+ <div class="col-3 col-m-3">
+
+ <p class="label">Wochentyp:</p>
+ <select class="plan" name="sel_woche" id="sel_woche" onChange="zeigePlan()" margin: 0% 7%; size="1"><optgroup><option value="A">A-Woche</option><option selected="selected" value="B">B-Woche</option></optgroup></select>
+ </div>
+ </div>
+<!-- Ende Abfrage responsive -->
+ <span class="noprint"><p style="color:red; margin:4px 0px; font-weight:bold;">Achtung diverse Änderungen zum 02.11.2020!!</p></span>
+<div class="plan"> <!-- Beginn Stundenplan-Tabelle -->
+ <table class="plan">
+
+ <thead>
+ <tr class="onlyprint">
+ <th class="titel" colspan="6">A-Woche-Stundenplan von Schüler/in Finn B.<span class="noprint"> <img src="images/help.gif" title="Schüler/in Finn Behrens (Q2-BRB)" /></span> (Q2-BRB)</th>
+ </tr>
+ <tr class="onlyprint">
+ <th class="std">S\T</th>
+ <th class="wotag">Montag</th>
+ <th class="wotag">Dienstag</th>
+ <th class="wotag">Mittwoch</th>
+ <th class="wotag">Donnerstag</th>
+ <th class="wotag">Freitag</th>
+
+ </tr>
+ </thead>
+ <tbody>
+<tr class="plan onlyprint"><th class="std">1</th><td class="plan">(G2) IF-GK2 KOW A310</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G5) D-GK6 DAN A008</td><td class="plan"></td><td class="plan">(L1) PL-LK1 BRB A207</td></tr><tr class="plan onlyprint"><th class="std">2</th><td class="plan">(G2) IF-GK2 KOW A310</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G5) D-GK6 DAN A008</td><td class="plan"></td><td class="plan">(L1) PL-LK1 BRB A207</td></tr><tr class="plan onlyprint"><th class="std">3</th><td class="plan">(G3) GZ-GK1 TSA A205</td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G8) E-GK1 KUR B004</td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">4</th><td class="plan">(G3) GZ-GK1 TSA A205</td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G8) E-GK1 KUR B004</td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">5</th><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan"></td><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan">(L2) M-LK2 BRU B125</td></tr><tr class="plan onlyprint"><th class="std">6</th><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan"></td><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan">(L2) M-LK2 BRU B125</td></tr><tr class="plan onlyprint"><th class="std">7</th><td class="plan"></td><td class="plan">(G8) E-GK1 KUR B208</td><td class="plan"></td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan">(G3) GZ-GK1 TSA A205</td></tr><tr class="plan onlyprint"><th class="std">8</th><td class="plan"></td><td class="plan"></td><td class="plan">(G4) BB-GK1 DEMR GOE</td><td class="plan"></td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">9</th><td class="plan"></td><td class="plan"></td><td class="plan">(G4) BB-GK1 DEMR GOE</td><td class="plan"></td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">10</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">11</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr><tr class="plan onlyprint"><th class="std">12</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr>
+ <tr class="onlyprint">
+ <th colspan="6">&nbsp;</th>
+ </tr>
+ </tbody>
+
+ <thead>
+ <tr>
+ <th class="titel" colspan="6"><span style="color:red;">B-Woche-</span>Stundenplan von Schüler/in Finn B.<span class="noprint"> <img src="images/help.gif" title="Schüler/in Finn Behrens (Q2-BRB)" /></span> (Q2-BRB)</th>
+ </tr>
+ <tr>
+ <th class="std">S\T</th>
+ <th class="wotag">Montag</th>
+ <th class="wotag">Dienstag</th>
+ <th class="wotag">Mittwoch</th>
+ <th class="wotag">Donnerstag</th>
+ <th class="wotag">Freitag</th>
+
+ </tr>
+ </thead>
+ <tbody>
+<tr class="plan"><th class="std">1</th><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G5) D-GK6 DAN A102</td><td class="plan">(G8) E-GK1 KUR B208</td><td class="plan">(G2) IF-GK2 KOW A308</td></tr><tr class="plan"><th class="std">2</th><td class="plan">(G7) PH-GK1 KRD B127</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G5) D-GK6 DAN A102</td><td class="plan">(G8) E-GK1 KUR B208</td><td class="plan">(G2) IF-GK2 KOW A308</td></tr><tr class="plan"><th class="std">3</th><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan"></td><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G1) R0-GK1 FOM A209</td></tr><tr class="plan"><th class="std">4</th><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan"></td><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan">(G1) R0-GK1 FOM A209</td></tr><tr class="plan"><th class="std">5</th><td class="plan">(G5) D-GK6 DAN A106</td><td class="plan"></td><td class="plan">(G4) BB-GK1 DEMR BN1</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G3) GZ-GK1 TSA A205</td></tr><tr class="plan"><th class="std">6</th><td class="plan">(G5) D-GK6 DAN A106</td><td class="plan"></td><td class="plan">(G4) BB-GK1 DEMR BN1</td><td class="plan">(L2) M-LK2 BRU B125</td><td class="plan">(G3) GZ-GK1 TSA A205</td></tr><tr class="plan"><th class="std">7</th><td class="plan"></td><td class="plan">(G3) GZ-GK1 TSA A207</td><td class="plan"></td><td class="plan">(G1) R0-GK1 FOM A209</td><td class="plan">(G8) E-GK1 KUR B206</td></tr><tr class="plan"><th class="std">8</th><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan"></td><td class="plan">(G2) IF-GK2 KOW A308</td><td class="plan"></td><td class="plan"></td></tr><tr class="plan"><th class="std">9</th><td class="plan">(L1) PL-LK1 BRB A207</td><td class="plan"></td><td class="plan">(G2) IF-GK2 KOW A308</td><td class="plan"></td><td class="plan"></td></tr><tr class="plan"><th class="std">10</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr><tr class="plan"><th class="std">11</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr><tr class="plan"><th class="std">12</th><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td><td class="plan"></td></tr>
+ </tbody>
+
+ </table>
+ </div> <!-- Ende Stundenplan-Tabelle -->
+
+ <div style="margin-top: 6px;"> <!-- Beginn Footer -->
+ <!-- Footer nur für den Ausdruck: -->
+ <div class="onlyprint label center">
+ SLP-PlanInfo v2.8.5 (c) Nov 2020 SLP-CodingTeam c/o Ziemke
+ .:. gedruckt am 15.11.2020
+ </div>
+
+ <!-- Footer responsiv: -->
+ <div class="row noprint label center">
+ <div class="col-4">
+ <span style="font-weight:bold; color:black; color:black;">Lizenz bis 01.11.2021: </span>
+ SLP-PlanInfo&nbsp;v2.8.5
+ [<a href="planinfo_eingabe-tipps.pdf" target="PlanInfo-Tipps" style="background-color: orange;">Tipps</a>]&nbsp;<a href="https://www.youtube.com/channel/UCF76sagowjK7cQKync3ONmw/videos" target="_blank" title="NEU: SLP-PlanInfo-Anleitungen auf dem YouTube-Kanal SLP SelbstLernPortal"><image src="../images/logo_youtube.png" style="height:1.2em; vertical-align:middle;"></a>
+ </div>
+ <div class="col-4">
+ (c) Nov 2020 SLP-CodingTeam c/o Ziemke
+ [<a href="../impressum.htm" target="_blank" >Impressum</a>]&nbsp;[<a href="../datenschutz.pdf" target="_blank" >Datenschutz</a>]
+ </div>
+ <div class="col-4">
+ [<a href="planinfo_history.php" target="_blank" >Info/History</a>]&nbsp;[<a href="planinfo_hinweise.pdf" target="_blank" >Manual</a>]&nbsp;[<a href="planinfo_login.php?ug=lev-llg&loginAs=admin" target="_blank" >Admin</a>]&nbsp;[<a href="planinfo_login.php?ug=lev-llg&loginAs=orga" target="_blank" >Orga-Tools</a>]
+ </div>
+ </div>
+ </div> <!-- Ende Footer -->
+
+ <script>
+ // falls aber das Objekt-Select existiert, dann dieses fokusieren,
+ // um das Blättern mit Pfeiltasten zu ermöglichen:
+ obj=document.getElementById("objektwahl");
+ if(obj) {
+ obj.focus();
+ } else {
+ obj=document.getElementById("search");
+ // Falls es das Schnellsuche-Eingabefeld (also NICHT die Auswahl) gibt,
+ // dann dieses fokusieren, um Eingaben direkt dorthin zu leiten:
+ // ABER NICHT auf mobilen Geräten, da sonst die Tastatur eingeblendet wird!
+ //if(obj && (typeof(document.ontouchstart) != "undefined")) obj.focus();
+ // ABER: ohne Focus keine Grün-Färbung des Eingabefeldes, also weiterhin:
+ if(obj) obj.focus();
+ }
+ </script>
+
+<!-- FORTSETZUNG HTML -->
+
+ <script language="JavaScript">
+ <!--
+ function getParmVal (key) {
+ ret = '';
+ if ((key != '') && (document.URL.indexOf('?') > -1)) {
+ parmS = document.URL.slice(document.URL.indexOf('?')+1);
+ parmA = parmS.split('&');
+ // Parameter key=xxx finden:
+ for (var i = 0; i < parmA.length; i++) {
+ tmp = parmA[i].split('=');
+ if (tmp[0] == key)
+ ret = tmp[1];
+ }
+ }
+ return ret;
+ }
+
+ function pruefeCookiesErlaubt() {
+ if( ! navigator.cookieEnabled ) {
+ info = 'Cookies sollten erlaubt sein,\nansonsten wird für den nächsten Besuch\ndie Schulauswahl nicht gespeichert.';
+ } else if( navigator.cookieEnabled ) {
+ info = '';
+ // ok
+ } else {
+ info = 'Die Cookie-Einstellung des Browsers ist nicht feststellbar.\nBitte überprüfen Sie selbst,\ndass Cookies erlaubt sind (empfohlen).';
+ }
+ if (info != '') alert (info);
+ }
+
+ function bildeObjektWahl() {
+ obj = document.getElementById("artwahl");
+ selart = obj[obj.selectedIndex].value;
+//alert ('Selektiert: '+selart);
+ // Parameter abschneiden:
+ uri = document.URL;
+ if (document.URL.indexOf('?')>-1)
+ uri = document.URL.slice(0, document.URL.indexOf('?'));
+ ugparm = getParmVal ('ug');
+ if (ugparm != '') ugparm = "ug=" + ugparm;
+ //location.href=uri+"?artwahl="+selart;
+ location.href=uri+"?"+ugparm+"&artwahl="+selart;
+ }
+
+ /**
+ * @version 2018-04
+ */
+ function zeigePlan() {
+ ugparm = ''; // Parameter ug=[USER_LOWER]
+ dbparm = '';
+ scrollparm = '';
+ obj = document.getElementById("dbidx"); // Schnellsuche-Eingabefeld
+ if (obj && obj.value != '') {
+ // Soeben gelang eine Schnellsuche; nun ggf. WochenWahl gewünscht;
+ // also nach Wochenwechsel Plan zum vorherigen Schnellsuche-Ergebnis:
+ dbparm = '&dbidx=' + obj.value;
+ }
+ artparm = '';
+ obj = document.getElementById("artwahl");
+ if (obj) {
+ selart = obj[obj.selectedIndex].value;
+ if (obj.selectedIndex > 0)
+ artparm = "&artwahl="+selart;
+ }
+ objidx = 0; selobjekt = '';
+ objektparm = '';
+ obj = document.getElementById("objektwahl"); // SelObjekt heiß objektwahl!
+ if (obj && (obj.selectedIndex > 0)) {
+ // Schnellsuche-Zweitauswahl oder Objekt-Auswahl:
+ objselidx = obj.selectedIndex;
+ dbindex_ = obj.options[obj.selectedIndex].value;
+ dbparm = "&dbidx=" + dbindex_;
+ // ArtWahl getroffen, also keine Schnellsuche-Zweitauswahl:
+ if (artparm != '')
+ objektparm = "&objselid=" + objselidx;
+ }
+ wocheparm = '';
+ obj = document.getElementById("sel_woche");
+ if (obj) wocheparm = '&wochewahl='+obj.options[obj.selectedIndex].value;
+ scrollparm = "";
+ obj = document.getElementById("scrolling");
+ if (obj && (obj.value != ''))
+ scrollparm = '&scrolling=' + obj.value;
+//alert(scrollparm);
+
+ info =
+ 'DEBUG in zeigePlan(); alle Params:'
+ +'\nartparm = ['+artparm+']'
+ +'\nobjektparm = ['+objektparm+']'
+ +'\nwocheparm = ['+wocheparm+']'
+ +'\ndbparm = ['+dbparm+']'
+ ;
+ // Parameter abschneiden:
+ uri = document.URL;
+ if (document.URL.indexOf('?') > -1) {
+ // Parameter ug=xxx finden:
+ ugparm = getParmVal ('ug');
+ if (ugparm != '') ugparm = "&ug=" + ugparm;
+ uri = document.URL.slice(0, document.URL.indexOf('?'));
+ }
+ /*
+ if (selart.replace(/ /g, "") != '') {
+//alert(info+'\n THEN-Aufruf');
+ // parm = artparm+objektparm+wocheparm+dbparm;
+ parm = ugparm+artparm+objektparm+wocheparm+dbparm;
+ } else {
+ // bisher keine ArtWahl getroffen; für QuickSearch:
+ // location.href=uri+"?objektwahl="+obj.selectedIndex+"&objektid="+selobjekt;
+//alert(info+'\n ELSE-Aufruf');
+ //parm = artparm+objektparm+wocheparm+dbparm;
+ parm = ugparm+artparm+objektparm+wocheparm+dbparm;
+ }
+ */
+ parm = ugparm+artparm+objektparm+wocheparm+dbparm+scrollparm;
+//alert ('DEBUG in planinfo.inc/zeigePlan(): uri+?+parm='+uri + '?' + parm.substr(1));
+ location.href=uri + '?' + parm.substr(1);
+ }
+
+ /**
+ * prüft auf Pfeiltasten-Druck, falls Parameter dbidx existiert,
+ * und legt im Formular-Objekt mit Name scrolling ggf. den Wert prev oder next ab.
+ * @version 2018-04
+ */
+ function pruefeObjektwechsel(ereignis) {
+//document.getElementById("test").innerHTML = location.search.search(/&objektwahl=/g);
+ // if (location.search.search(/&objektwahl=/g)>-1) {
+//alert("Start von pruefeObjektWechsel()");
+ if (location.search.search(/&dbidx=/g)>-1) {
+//alert("location.search="+location.search);
+ // nur bei bereits erfolgter Objektwahl:
+ if (!ereignis)
+ ereignis = window.event;
+ if (ereignis.which) {
+ tastencode = ereignis.which;
+ } else if (ereignis.keyCode) {
+ tastencode = ereignis.keyCode;
+ }
+
+ // Falls Pfeil auf oder Pfeil ab gedrückt, neuen Plan zeigen
+ if (tastencode > 36 && tastencode < 41) {
+//alert("tastencode="+tastencode);
+ obj = document.getElementById("scrolling");
+ obj.value = "";
+ if (tastencode == 38 || tastencode == 37) {
+ obj.value = "prev";
+//alert("Pfeil links oder oben");
+ }
+ if (tastencode == 40 || tastencode == 39) {
+ obj.value = "next";
+//alert("Pfeil rechts oder unten");
+ }
+ /*
+ obj.options[obj.selectedIndex].select = true;
+ */
+//alert("document.getElementById(scrolling).value="+document.getElementById("scrolling").value);
+ zeigePlan();
+ }
+ }
+ }
+
+ function setzeFocus() {
+ //if (location.search.search(/&objektwahl=/g)>-1) {
+ if (location.search.search(/&objselid=/g)>-1) {
+ obj = document.getElementById("objektwahl");
+ obj.focus();
+ //obj.select();
+ //obj[obj.selectedIndex].caption.select();
+ //document.getElementById("objektwahl").select();
+ }
+ }
+ // nur für IE nötig:
+ //if (document.all)
+ // setzeFocus();
+ document.onkeyup = pruefeObjektwechsel;
+ //document.onkeyup = function(){alert("TEST");};
+ //-->
+ </script>
+ <noscript>JavaScript ist nicht aktiviert!</noscript>
+ </body>
+</html>
diff --git a/src/slp/html.rs b/src/slp/html.rs
new file mode 100644
index 0000000..f5fa490
--- /dev/null
+++ b/src/slp/html.rs
@@ -0,0 +1,139 @@
+use std::convert::TryFrom;
+
+use super::SLP;
+use crate::types::*;
+use crate::Error;
+
+use log::trace;
+use markup5ever_rcdom::{Handle, Node, NodeData};
+
+pub(crate) fn parse(handle: &Handle) -> Result<SLP, Error> {
+ let node: &Node = handle;
+ let node = &node.children.borrow()[1];
+ if node.children.borrow().len() < 2 {
+ return Err(Error::SlpParse("html is to short".to_string()));
+ }
+ if !check_title(&node.children.borrow()[0]) {
+ return Err(Error::SlpParse("Planinfo auth failed".to_string()));
+ }
+
+ let node = &node.children.borrow()[2];
+ for v in node.children.borrow().iter() {
+ if let NodeData::Element {
+ ref name,
+ ref attrs,
+ ..
+ } = v.data
+ {
+ let attrs = &attrs.borrow();
+ if name.local.to_string() == "div" {
+ for attr in attrs.iter() {
+ if attr.name.local.to_string() == "class" && attr.value.to_string() == "plan" {
+ return parse_dom_div(v);
+ }
+ }
+ }
+ }
+ }
+
+ Err(Error::SlpParse("no planinfo dom found".to_string()))
+}
+
+fn parse_dom_div(node: &Node) -> Result<SLP, Error> {
+ let mut kind = 0; // TODO: ?
+ for v in node.children.borrow().iter() {
+ if let NodeData::Element { ref name, .. } = v.data {
+ if name.local.to_string() == "table" {
+ let mut A = true; // TODO: ?
+ let mut first_run = true; // TODO: ?
+ let mut entry_name = String::new(); // TODO: ?
+ let mut course_string = String::new(); // TODO: ?
+ for v in v.children.borrow().iter() {
+ if let NodeData::Element { ref name, .. } = v.data {
+ if name.local.to_string() == "thead" {
+ parse_dom_div_thead(v)?;
+ }
+ }
+ }
+ }
+ }
+ }
+ todo!()
+}
+
+fn parse_dom_div_thead(node: &Node) -> Result<Vec<String>, Error> {
+ // TODO: Ok type?
+ let mut ret = Vec::new();
+ for v in node.children.borrow().iter() {
+ if let NodeData::Element { ref name, .. } = v.data {
+ if name.local.to_string() == "tr" {
+ for v in v.children.borrow().iter() {
+ if let NodeData::Element {
+ ref name,
+ ref attrs,
+ ..
+ } = v.data
+ {
+ let attrs = attrs.borrow();
+ for attr in attrs.iter() {
+ if attr.name.local.to_string() == "class"
+ && attr.value.to_string() == "titel"
+ {
+ for v in v.children.borrow().iter() {
+ if let NodeData::Text { ref contents } = v.data {
+ let contents = contents.borrow();
+ let contents = contents.trim();
+ ret.push(contents.to_string());
+ } else if let NodeData::Element { ref name, .. } = v.data {
+ println!("found element: {}", name.local);
+ //let v = &v.children.borrow()[0];
+ if let Some(NodeData::Element {
+ ref attrs,
+ ref name,
+ ..
+ }) = v.children.borrow().get(1).map(|v| &v.data)
+ {
+ println!("found: {}", name.local.to_string());
+ for attr in attrs.borrow().iter() {
+ if attr.name.local.to_string() == "title" {
+ ret.push(attr.value.to_string());
+ }
+ }
+ } else if let Some(NodeData::Text { ref contents }) =
+ v.children.borrow().get(0).map(|v| &v.data)
+ {
+ ret.push(contents.borrow().to_string());
+ } else {
+ trace!("what am I??: {:?}", v);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ Ok(ret)
+}
+
+/// test if auth was successfully
+pub(crate) fn check_title(handle: &Handle) -> bool {
+ let node: &Node = handle;
+ for v in node.children.borrow().iter() {
+ if let NodeData::Element { ref name, .. } = v.data {
+ if name.local.to_string() == "title" {
+ let node = &v.children.borrow()[0];
+ if let NodeData::Text { ref contents } = node.data {
+ if contents.borrow().ends_with("Anzeige") {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
diff --git a/src/slp/mod.rs b/src/slp/mod.rs
index e69de29..620f74e 100644
--- a/src/slp/mod.rs
+++ b/src/slp/mod.rs
@@ -0,0 +1,41 @@
+use crate::types::*;
+use crate::Error;
+
+use html5ever::parse_document;
+use html5ever::tendril::TendrilSink;
+use markup5ever_rcdom::RcDom;
+
+mod html;
+
+#[derive(Debug, Eq, PartialEq, Clone)]
+pub struct SLP {
+ pub surname: String,
+ pub name: String,
+
+ pub table_a: [Vec<SLPEntry>; 5],
+}
+
+impl SLP {
+ /// parse slp content
+ pub fn parse(html: &str) -> Result<SLP, Error> {
+ let dom = parse_document(RcDom::default(), Default::default())
+ .from_utf8()
+ .read_from(&mut html.as_bytes())?;
+
+ html::parse(&dom.document)
+ }
+}
+
+#[cfg(test)]
+mod test {
+ use super::SLP;
+
+ #[test]
+ fn read_behrens_slp() {
+ let html = std::fs::read_to_string("./src/slp/behrens_slp.html").unwrap();
+ let slp = SLP::parse(&html).unwrap();
+
+ println!("slp: {:?}", slp);
+ // TODO: asserts
+ }
+}