From c533d2c1d579906924237e41b6d71e1601deecae Mon Sep 17 00:00:00 2001 From: davidpkj Date: Tue, 23 Apr 2024 21:45:37 +0200 Subject: mega commit: ics, readme updates, easier usage --- src/main.js | 101 +++++------------------------------------------------------- 1 file changed, 7 insertions(+), 94 deletions(-) (limited to 'src/main.js') 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 = "`; - -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 += `` + 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 += ``; - } else { - let name = el.name == "BUFFER" ? "" : `
${el.name}`; - let raum = el.raum == "BUFFER" ? "" : `${el.raum}`; - - res += `${name}${raum}`; - } - - timeout[day] = el.runtime - 1; - tage_runtimes[day].splice(0, 1); - } - - res += "" - } - - return res + return runtimes(tage, tage_runtimes) } - -let html = ` -${c.style} -

Persönlicher Stundenplan von ${c.student} für das ${c.semester}. Stand: ${date}.

- - - - - - - - - - ${main()} -
UhrzeitMontagDienstagMittwochDonnerstagFreitag
-
-Hinweise: -${hinweise} -`; - -html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => { - // fs.writeFileSync("test.html", html) - fs.writeFileSync(c.filename, pdfBuffer); -}); -- cgit v1.2.3