First calendar

node v14.20.1
version: 3.0.0
endpointsharetweet
const ics = require("ics"); const mime = require("mime"); const express = require("express"); const app = express(); const port = 3000; app.get("/ccgs", async (req, res) => { try { const ccgse = await ccgsEvents(); console.log(ccgse); const events = await ics.createEvents(ccgse); console.log(events.value); res.setHeader("Content-Type", mime.getType("ics")); res.send(events.value); } catch (error) { console.log(error); res.error(error); } }); app.get("/st-hildas", async (req, res) => { try { const sch = await shasgEvents(); console.log(sch); const events = await ics.createEvents(sch); console.log(events.value); res.setHeader("Content-Type", mime.getType("ics")); res.send(events.value); } catch (error) { console.log(error); res.error(error); } }); const term = (start, end, school, termNumber) => { const title = `${school.abbreviation} term ${termNumber}`; const description = `${school.longName} term ${termNumber}`; const event = { start: start, end: end, title: title, description: description, location: school.location, url: school.calendarUrl, geo: school.geo, }; return event; }; const midtermBreak = (start, end, school, termNumber) => { const title = `${school.abbreviation} term ${termNumber} mid-term break`; const description = title; const event = { start: start, end: end, title: title, description: description, location: school.location, url: school.calendarUrl, geo: school.geo, }; return event; }; const holiday = (start, end, school, boundingTerms, customDescription) => { var title; if (customDescription) { title = `${school.abbreviation} ${customDescription} holiday`; } else { title = `${school.abbreviation} term ${boundingTerms[0]}-${boundingTerms[1]} holiday`; } const description = ""; const event = { start: start, end: end, title: title, description: description, location: school.location, url: school.calendarUrl, geo: school.geo, }; return event; }; const customEvent = (start, end, school, customDescription) => { const title = `${school.abbreviation} - ${customDescription}`; const description = title; const event = { start: start, end: end, title: title, description: description, location: school.location, url: school.calendarUrl, geo: school.geo, }; return event; }; const school = (abbreviation, longName, calendarUrl, geo, location) => { return { abbreviation, longName, calendarUrl, geo, location, }; }; const ccgsEvents = async () => { // https://www.ccgs.wa.edu.au/wp-content/uploads/2022/04/Term-dates-2023-website.pdf const ccgs = school( "CCGS", "Christ Church Grammar School", "https://www.ccgs.wa.edu.au/wp-content/uploads/2021/11/Term-dates-2022-website-vs-V4.pdf", { lat: -31.98642, lon: 115.777427 }, "Christ Church Grammar School, Queenslea Drive, Claremont WA 6010, Australia" ); const term2 = term([2022, 4, 26], [2022, 7, 2], ccgs, 2); const term3 = term([2022, 7, 19], [2022, 9, 24], ccgs, 3); const term4 = term([2022, 10, 11], [2022, 12, 2], ccgs, 4); const break2 = midtermBreak([2022, 6, 3], [2022, 6, 7], ccgs, 2); const break3 = midtermBreak([2022, 8, 19], [2022, 8, 23], ccgs, 3); const holiday2 = holiday([2022, 7, 2], [2022, 7, 19], ccgs, [2, 3]); const holiday3 = holiday([2022, 9, 24], [2022, 10, 11], ccgs, [3, 4]); const endOfTerm4 = customEvent( [2022, 12, 1], [2022, 12, 2], ccgs, "Years 7 to 11 Final Assembly and Prize Giving. Term 4 ends for Senior School" ); const term1_23 = term([2023, 1, 30], [2023, 4, 6], ccgs, 1); const term2_23 = term([2023, 4, 26], [2023, 6, 30], ccgs, 2); const term3_23 = term([2023, 7, 18], [2023, 9, 22], ccgs, 3); const term4_23 = term([2023, 10, 10], [2023, 12, 1], ccgs, 4); const break1_23 = midtermBreak([2023, 3, 3], [2023, 3, 7], ccgs, 1); const break2_23 = midtermBreak([2023, 6, 2], [2023, 6, 6], ccgs, 2); const break3_23 = midtermBreak([2023, 8, 18], [2023, 8, 22], ccgs, 3); const holiday1_23 = holiday([2023, 4, 7], [2023, 4, 25], ccgs, [1, 2]); const holiday2_23 = holiday([2023, 7, 1], [2023, 7, 18], ccgs, [2, 3]); const holiday3_23 = holiday([2023, 9, 23], [2023, 10, 10], ccgs, [3, 4]); const endOfTerm4_23 = customEvent( [2023, 12, 1], [2023, 12, 2], ccgs, "Years 7 to 11 Final Assembly and Prize Giving. Term 4 ends for Preparatory and Senior School" ); return [ term2, term3, term4, break2, break3, holiday2, holiday3, endOfTerm4, term1_23, term2_23, term3_23, term4_23, break1_23, break2_23, break3_23, holiday1_23, holiday2_23, holiday3_23, endOfTerm4_23, ]; }; const shasgEvents = async () => { const sch = school( "St Hilda's", "St Hilda's Anglican School for Girls", "https://www.sthildas.wa.edu.au/student-life/key-dates/", { lat: -32.010718361690266, lon: 115.76309333684294 }, "St Hilda's Anglican School for Girls, Bay View Terrace, Mosman Park WA 6012, Australia" ); const term2 = term([2022, 4, 27], [2022, 7, 2], sch, 2); const term3 = term([2022, 7, 26], [2022, 9, 24], sch, 3); const term4 = term([2022, 10, 11], [2022, 12, 7], sch, 4); const break2 = midtermBreak([2022, 6, 3], [2022, 6, 7], sch, 2); const break3 = midtermBreak([2022, 8, 19], [2022, 8, 23], sch, 3); const holiday2 = holiday([2022, 7, 2], [2022, 7, 26], sch, [2, 3]); const holiday3 = holiday([2022, 9, 24], [2022, 10, 11], sch, [3, 4]); const endOfTerm4 = customEvent( [2022, 12, 6], [2022, 12, 7], sch, "Term 4 ends for Senior School (lunchtime)" ); return [term2, term3, term4, break2, break3, holiday2, holiday3, endOfTerm4]; }; app.listen(port, () => { console.log(`Example app listening on port ${port}`); });
Loading…

no comments

    sign in to comment