import { exec } from 'child_process'; const nodemailer = require('nodemailer'); exec('iching divine', (error, stdout, stderr) => { console.log(`Begin`); if (error) { console.error(`Error: ${error.message}`); return; } if (stderr) { console.error(`Stderr: ${stderr}`); return; } //console.log(`Ergebnis:\n${stdout}`); console.log(`Send E-Mail`); sendEmail(stdout); sleep(); }); // Create Transporter const transporter = nodemailer.createTransport({ host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP port: 1025, // Standard-MailHog SMTP-Port secure: false // MailHog needs no encryption }); // Send E-Mail async function sendEmail(content: string) { try { const info = await transporter.sendMail({ from: '"The Oracle" ', to: "Christopher.Hase@telekom.com;test@mailhog.local", subject: "Your Horoscope Is Ready", text: content, //html: "

${content}

" html: html(content) //html: content }); console.log("E-Mail sent: ", info.messageId); } catch (error) { console.error("Error Sending E-Mail:", error); } } //Sleep. To avoid issue in pod: Completed -> Terminated -> CrashLoopBackOff async function sleep() { console.log("Go to sleep: ", new Date().toISOString()); // sleep 1h (3600000 ms) setTimeout(() => { sleep(); // recursion after 1h }, 3600000); } //node structure for the Parse Tree interface Node { type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ; child?: Node; value?: string; //level?: number; // Für Header } function html(inputText: string): string { // Parse Tree erstellen & HTML generieren const parseTree = parse(inputText); const htmlOutput = render(parseTree); return htmlOutput; } //function parse(input: string): string { function parse(input: string): Node { console.log("Parse input text"); const root: Node = { type: "Root"}; //, child: {} var currentNode: Node = root; const lines = input.split("\n"); for (const line of lines) { if (line.startsWith("Hexagram")) { const hexagram: Node = { type: "Hexagram"}; currentNode.child = hexagram; currentNode = hexagram; currentNode.value = "

" + line + "

"; //TODO: formattierung } if (line.startsWith("Judgement")) { const judgement: Node = { type: "Judgement"}; currentNode.child = judgement; currentNode = judgement; currentNode.value = "

" + line + "

"; //TODO: formattierung } if (line.startsWith("Images")) { const images: Node = { type: "Images"}; currentNode.child = images; currentNode = images; currentNode.value = "

" + line + "

"; //TODO: formattierung } if (line.startsWith("changingLines") && currentNode.type != "ChangingLines") { const changingLines: Node = { type: "ChangingLines"}; currentNode.child = changingLines; currentNode = changingLines; currentNode.value = line + "
"; //TODO: formattierung } else { currentNode.value?.concat(line + "
"); } } // Bearbeite jede Zeile //const processedLines = lines.map(line => processLine(line)); //processedLines.join("\n"); return root; } function render(node: Node): string { if (typeof node.type == "undefined") { console.log("...finished...") return ""; } console.log("Render node " + node.type); var outputHTML: string = ""; // type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ; switch (node.type) { case "Root": return render(node.child!); //case "Hexagram": default: outputHTML = "

" + node.value + "

"; outputHTML.concat(render(node.child!)); return outputHTML; } //return ""; } /* //TODO: process every line... function processLine(inputLine: string): string { if (inputLine.startsWith('Hexagram')) { return processLineHexagram(inputLine); } //return input + "\n"; //"

${content}

" return "

" + inputLine + "

"; } function processLineHexagram(inputLine: string): string { return "

" + inputLine + "

"; }*/