aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/files.js20
-rw-r--r--src/main.js49
-rw-r--r--src/univis.js41
-rw-r--r--src/variables.js143
4 files changed, 87 insertions, 166 deletions
diff --git a/src/files.js b/src/files.js
new file mode 100644
index 0000000..970d28d
--- /dev/null
+++ b/src/files.js
@@ -0,0 +1,20 @@
+import * as yml from "js-yaml"
+import * as fs from "fs"
+
+const dir = "./public";
+
+function readConfig() {
+ return yml.load(fs.readFileSync(`${dir}/config.yaml`, 'utf8'));
+}
+
+function readStyle() {
+ return fs.readFileSync(`${dir}/style.css`, 'utf8');
+}
+
+export function readXML() {
+ return fs.readFileSync(`${dir}/data.xml`, 'utf8');
+}
+
+export const c = readConfig();
+
+c.style = `<style>${readStyle()}</style>`; \ No newline at end of file
diff --git a/src/main.js b/src/main.js
index 5b326d7..c3cbec9 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,10 +1,10 @@
import * as fs from "fs"
import * as html_to_pdf from "html-pdf-node"
-import * as v from './variables.js'
+import { c } from './files.js'
let hinweise = "<ul>";
-for (let hinweis of v.hinweise) {
+for (let hinweis of c.hinweise) {
hinweise += `<li>${hinweis}</li>`;
}
hinweise += `</ul>`;
@@ -133,14 +133,19 @@ function main() {
let tage = structuredClone(ctage);
let tage_runtimes = structuredClone(ctage);
- for (let eintrag of v.eintraege) {
- for (let termin of eintrag.termine) {
- tage[termin.wochentag].push({
- "name": eintrag.name,
- "raum": termin.raum,
- "von": termin.von,
- "bis": termin.bis,
- })
+ for (let eintrag of c.eintraege) {
+ let eintragName = Object.keys(eintrag)[0];
+ eintrag = eintrag[eintragName]
+
+ for (let veranstaltung in eintrag) {
+ for (let termin of eintrag[veranstaltung]) {
+ tage[termin[0]].push({
+ "name": `${eintragName.toString()} / ${veranstaltung.toString()}`,
+ "raum": termin[3],
+ "von": termin[1].replace("h", ":"),
+ "bis": termin[2].replace("h", ":"),
+ })
+ }
}
}
@@ -167,7 +172,7 @@ function main() {
let el = tage_runtimes[day][0];
- if (el.name == "BLOCKED" && el.raum == "BLOCKED") {
+ if (el.name.includes("BLOCKED") && el.raum == "BLOCKED") {
res += `<td rowspan="${el.runtime}" class="block"></td>`;
} else {
let name = el.name == "BUFFER" ? "" : `<div><span>${el.name}</span>`;
@@ -183,31 +188,29 @@ function main() {
res += "</tr>"
}
- // console.log(res)
-
return res
}
let html = `
-${v.style}
-<p>Persönlicher Stundenplan von ${v.student} für das ${v.semester}. Stand: ${date}.</p>
+${c.style}
+<p>Persönlicher Stundenplan von ${c.student} für das ${c.semester}. Stand: ${date}.</p>
<table>
<tr>
- <th> Uhrzeit </th>
- <th class="tag"> Montag </th>
- <th class="tag"> Dienstag </th>
- <th class="tag"> Mittwoch </th>
- <th class="tag"> Donnerstag </th>
- <th class="tag"> Freitag </th>
+ <th>Uhrzeit</th>
+ <th class="tag">Montag</th>
+ <th class="tag">Dienstag</th>
+ <th class="tag">Mittwoch</th>
+ <th class="tag">Donnerstag</th>
+ <th class="tag">Freitag</th>
</tr>
${main()}
</table>
<br>
-<u> Hinweise: </u>
+<em>Hinweise:</em>
${hinweise}
`;
html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => {
// fs.writeFileSync("test.html", html)
- fs.writeFileSync(v.filename, pdfBuffer);
+ fs.writeFileSync(c.filename, pdfBuffer);
});
diff --git a/src/univis.js b/src/univis.js
new file mode 100644
index 0000000..f770bd7
--- /dev/null
+++ b/src/univis.js
@@ -0,0 +1,41 @@
+import * as xml from "xml-js"
+
+import { readXML } from "./files.js"
+
+function getRoomName(key) {
+ for (let room of res.Room) {
+ if (room._attributes.key == key) {
+ return room.short._text;
+ }
+ }
+
+ return "?";
+}
+
+function serializeLecture(lecture) {
+ let name = lecture.short?._text ?? lecture.name._text
+
+ for (let term in lecture.terms) {
+ let t = lecture.terms[term];
+
+ if (!t.starttime) continue;
+
+ let von = t.starttime._text.replace(":", "h");
+ let bis = t.endtime._text.replace(":", "h");
+
+ let raum = getRoomName(t.room.UnivISRef._attributes.key);
+
+ console.log(`${name}, ${von}, ${bis}, ${raum}`);
+ }
+}
+
+let data = readXML();
+let res = (xml.xml2js(data, {compact: true})).UnivIS;
+
+let semester = res._attributes.semester;
+
+console.log("semester: " + semester)
+
+for (let lecture of res.Lecture) {
+ serializeLecture(lecture)
+} \ No newline at end of file
diff --git a/src/variables.js b/src/variables.js
deleted file mode 100644
index bf98ca1..0000000
--- a/src/variables.js
+++ /dev/null
@@ -1,143 +0,0 @@
-// Dont touch this
-class Eintrag {
- constructor(name, termine) {
- this.name = name;
- this.termine = termine;
- }
-}
-
-class Termin {
- constructor(wochentag, raum, von, bis) {
- this.wochentag = wochentag;
- this.raum = raum;
- this.von = von;
- this.bis = bis;
- }
-}
-
-// You may touch this
-export const student = "David Penkowoj";
-export const semester = "Sommersemester 2024";
-export const filename = `Stundenplan-${semester.replace(" ", "-")}.pdf`;
-
-export const hinweise = [
- "Mensabetrieb: 11:15 - 14:15 Uhr + 00:15 min",
- "GET 2 / V am 23.05. & 04.07. im V1",
- "GET 2 / Ü am 24.05. im T S2",
- "FuQ / V am 24.05. im T S1",
-];
-
-export const eintraege = [
- new Eintrag("GET 2 / Ü", [
- new Termin("Mo", "AM S4", "12:00", "13:00"),
- new Termin("Fr", "AM S4", "11:30", "13:00")
- ]),
- new Eintrag("GET 2 / V", [
- new Termin("Di", "H1", "08:30", "10:00"),
- new Termin("Do", "Z 1/2", "08:30", "10:00")
- ]),
- new Eintrag("TGI 1 / V", [
- new Termin("Mi", "AM 1", "08:15", "09:45"),
- ]),
- new Eintrag("TGI 1 / Ü", [
- new Termin("Do", "AM 1", "15:00", "16:00"),
- ]),
- new Eintrag("TGI 1 / Prak. Gr. 2", [
- new Termin("Di", "ITI 131", "14:30", "17:30"),
- ]),
- new Eintrag("Pho / V", [
- new Termin("Fr", "T 1", "08:30", "10:00"),
- ]),
- new Eintrag("Pho / Ü", [
- new Termin("Mi", "AM 1", "12:00", "13:00"),
- ]),
- new Eintrag("Ana 2 / V", [
- new Termin("Di", "AM 1", "12:30", "14:00"),
- ]),
- new Eintrag("Ana 2 / Ü", [
- new Termin("Do", "H 1", "16:15", "17:15"),
- ]),
- new Eintrag("Ana 2 / Helpdesk", [
- new Termin("Di", "O-Sync", "18:00", "19:00"),
- new Termin("Mi", "O-Sync", "18:00", "19:00")
- ]),
- new Eintrag("EiBMO / V", [
- new Termin("Mi", "H 1", "14:00", "16:00"),
- ]),
- new Eintrag("EiBMO / Ü", [
- new Termin("Mi", "H 1", "16:00", "17:00"),
- ]),
- new Eintrag("FuQ / V", [
- new Termin("Fr", "AM 4", "10:00", "11:30"),
- ]),
- new Eintrag("FuQ / Ü", [
- new Termin("Di", "SI 4 (Minsky)", "11:00", "12:00"),
- ]),
- new Eintrag("BLOCKED", [
- new Termin("Mo", "BLOCKED", "13:00", "19:00"),
- new Termin("Do", "BLOCKED", "10:00", "15:00")
- ])
-];
-
-// You may touch this, if you know what you are doing
-export const style = `
-<style>
- * {
- font-weight: 300;
- font-family: "Abel", sans-serif;
- -webkit-print-color-adjust: exact;
-
- --entries-b: #ccc;
- --entries-f: #111;
- --headers-b: #333;
- --headers-f: #fff;
-
- --block: #ccc;
- }
-
- table {
- width: 100%;
- }
-
- table td, table tr {
- background: var(--headers-f);
- height: 4px;
- }
-
- table th, table td:not(:empty) {
- background-color: var(--entries-b);
- color: var(--entries-f);
- padding: 0.5em 1em;
- position: relative
- }
-
- table th {
- background-color: var(--headers-b);
- color: var(--headers-f);
- }
-
- table th.tag {
- width: 20%;
- }
-
- table td {
- font-size: 12px;
- }
-
- table td.block {
- background-image: repeating-linear-gradient(314deg, var(--block), var(--block) 10px, transparent 10px, transparent 20px);
- background-size: 99.9999999% 99.9999999%;
- border: 2px solid var(--block);
- }
-
- div {
- position: absolute;
- display: flex;
-
- top: 0.4em;
- left: 0.4em;
- width: calc(100% - 0.8em);
- justify-content: space-between;
- }
-</style>
-`;