aboutsummaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2024-04-23 21:45:37 +0200
committerdavidpkj <davidpenkow1@gmail.com>2024-04-23 21:45:37 +0200
commitc533d2c1d579906924237e41b6d71e1601deecae (patch)
tree667a9c455703672a4bd1ce282cda25d78a33412a /src/main.js
parentd09f40a732d65c222aefb2c9df4ddad3d0b66ed7 (diff)
mega commit: ics, readme updates, easier usage
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js101
1 files changed, 7 insertions, 94 deletions
diff --git a/src/main.js b/src/main.js
index 31183b2..4792319 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,22 +1,5 @@
-import * as fs from "fs"
-import * as html_to_pdf from "html-pdf-node"
-
import { c } from './files.js'
-let hinweise = "<ul>";
-for (let hinweis of c.hinweise) {
- hinweise += `<li>${hinweis}</li>`;
-}
-hinweise += `</ul>`;
-
-let date = new Date();
-date = date.toLocaleDateString("de-DE", {
- weekday: 'long',
- year: 'numeric',
- month: 'long',
- day: 'numeric',
-});
-
const ctage = {
"Mo": [],
"Di": [],
@@ -25,24 +8,13 @@ const ctage = {
"Fr": []
}
-const options = {
- format: 'A4',
- landscape: true,
- margin: {
- top: "0.5cm",
- right: "1cm",
- bottom: "1cm",
- left: "2cm",
- },
-};
-
// returns time difference in 15-minute intervalls
function timediff(a, b) {
const time = "1970-01-01 ";
return (new Date(time + a) - new Date(time + b)) / 1000 / 60 / 15;
}
-function gettimefromintervalls(x) {
+export function gettimefromintervalls(x) {
let y = 15 * x / 60 + 8
let z = y.toString().padStart(2, '0');
@@ -127,9 +99,7 @@ function bufferUp(tage) {
return tage;
}
-function main() {
- let res = "";
-
+export function prepare(forICS = false) {
let tage = structuredClone(ctage);
let tage_runtimes = structuredClone(ctage);
@@ -149,69 +119,12 @@ function main() {
}
}
+ if (forICS) {
+ return tage = sortTage(tage);
+ }
+
tage = bufferUp(tage, ctage);
tage = sortTage(tage);
- tage_runtimes = runtimes(tage, tage_runtimes)
-
- let timeout = {}
-
- // 1h has 4 15 minute intervalls: 08 to 19 means 44 intervalls
- for (let i = 0; i < 44; i++) {
- let mensa = "";
-
- if (11 < i && i < 25) mensa = "mensa1";
- if (25 < i && i < 27) mensa = "mensa2";
-
- res += `<tr class="${mensa}">` + gettimefromintervalls(i)
- for (let day in tage_runtimes) {
- if (timeout[day] > 0) {
- timeout[day]--;
- continue;
- }
-
- let el = tage_runtimes[day][0];
-
- if (el.name.includes("STYLECLASS")) {
- let styleclass = el.name.split("/")[1].trim().toLowerCase();
- res += `<td rowspan="${el.runtime}" class="${styleclass}"></td>`;
- } else {
- let name = el.name == "BUFFER" ? "" : `<div><span>${el.name}</span>`;
- let raum = el.raum == "BUFFER" ? "" : `<span>${el.raum}</span>`;
-
- res += `<td rowspan="${el.runtime}">${name}${raum}</td>`;
- }
-
- timeout[day] = el.runtime - 1;
- tage_runtimes[day].splice(0, 1);
- }
-
- res += "</tr>"
- }
-
- return res
+ return runtimes(tage, tage_runtimes)
}
-
-let html = `
-${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>
- </tr>
- ${main()}
-</table>
-<br>
-<em>Hinweise:</em>
-${hinweise}
-`;
-
-html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => {
- // fs.writeFileSync("test.html", html)
- fs.writeFileSync(c.filename, pdfBuffer);
-});