First calendar

node v14.19.2
version: 2.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 () => { 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" ); return [term2, term3, term4, break2, break3, holiday2, holiday3, endOfTerm4]; }; 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