From c94867ded69437a0cff705734076ec3938f998ed Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 15 Oct 2024 15:53:08 +0300 Subject: [PATCH] get regular refresh up and running --- calendars.json | 66 +++++++++++++++++++++++++------------------------- server.js | 11 ++++++--- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/calendars.json b/calendars.json index 8e50438..8d5d05e 100644 --- a/calendars.json +++ b/calendars.json @@ -1,34 +1,34 @@ { - "linkGroups": [ - { - "name": "Group 1", - "links": [ - { - "url": "https://example.com/calendar1.ics", - "prefix": "Calendar 1", - "overrideSummary": false - }, - { - "url": "https://example.com/calendar2.ics", - "prefix": "Calendar 2", - "overrideSummary": true - } - ] - }, - { - "name": "Group 2", - "links": [ - { - "url": "https://example.com/calendar3.ics", - "prefix": "Calendar 3", - "overrideSummary": false - }, - { - "url": "https://example.com/calendar4.ics", - "prefix": "Calendar 4", - "overrideSummary": true - } - ] - } - ] - } \ No newline at end of file + "linkGroups": [ + { + "name": "Group 1", + "links": [ + { + "url": "https://example.com/calendar1.ics", + "prefix": "Calendar 1", + "overrideSummary": false + }, + { + "url": "https://example.com/calendar2.ics", + "prefix": "Calendar 2", + "overrideSummary": true + } + ] + }, + { + "name": "Group 2", + "links": [ + { + "url": "https://example.com/calendar3.ics", + "prefix": "Calendar 3", + "overrideSummary": false + }, + { + "url": "https://example.com/calendar4.ics", + "prefix": "Calendar 4", + "overrideSummary": true + } + ] + } + ] +} \ No newline at end of file diff --git a/server.js b/server.js index a27917f..ba0a20d 100644 --- a/server.js +++ b/server.js @@ -132,9 +132,14 @@ async function updateMergedCalendar(){ const calendarsFile = 'calendars.json'; const calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8')); + // Check if calendarsData is defined and has the expected structure + if (!calendarsData || !calendarsData.linkGroups) { + throw new Error('Invalid calendars data structure'); + } + console.log(calendarsData); // Fetch calendar data for each link group - const promises = calendarsData.calendars.map((calendar) => { - return Promise.all(calendar.links.map((link) => { + const promises = calendarsData.linkGroups.map((linkGroup) => { + return Promise.all(linkGroup.links.map((link) => { return axios.get(link.url) .then((response) => { return { @@ -210,7 +215,7 @@ END:VEVENT } // Schedule a cron job to update the merged calendar every hour -cron.schedule('*/1 * * * *', () => { +cron.schedule('*/3 * * * *', () => { console.log('Updating merged calendar...'); updateMergedCalendar(); });