1
0
Fork 0

get regular refresh up and running

This commit is contained in:
Ryan Mwangi 2024-10-15 15:53:08 +03:00
parent 4cac613470
commit c94867ded6
2 changed files with 41 additions and 36 deletions

View File

@ -1,34 +1,34 @@
{ {
"linkGroups": [ "linkGroups": [
{ {
"name": "Group 1", "name": "Group 1",
"links": [ "links": [
{ {
"url": "https://example.com/calendar1.ics", "url": "https://example.com/calendar1.ics",
"prefix": "Calendar 1", "prefix": "Calendar 1",
"overrideSummary": false "overrideSummary": false
}, },
{ {
"url": "https://example.com/calendar2.ics", "url": "https://example.com/calendar2.ics",
"prefix": "Calendar 2", "prefix": "Calendar 2",
"overrideSummary": true "overrideSummary": true
} }
] ]
}, },
{ {
"name": "Group 2", "name": "Group 2",
"links": [ "links": [
{ {
"url": "https://example.com/calendar3.ics", "url": "https://example.com/calendar3.ics",
"prefix": "Calendar 3", "prefix": "Calendar 3",
"overrideSummary": false "overrideSummary": false
}, },
{ {
"url": "https://example.com/calendar4.ics", "url": "https://example.com/calendar4.ics",
"prefix": "Calendar 4", "prefix": "Calendar 4",
"overrideSummary": true "overrideSummary": true
} }
] ]
} }
] ]
} }

View File

@ -132,9 +132,14 @@ async function updateMergedCalendar(){
const calendarsFile = 'calendars.json'; const calendarsFile = 'calendars.json';
const calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8')); 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 // Fetch calendar data for each link group
const promises = calendarsData.calendars.map((calendar) => { const promises = calendarsData.linkGroups.map((linkGroup) => {
return Promise.all(calendar.links.map((link) => { return Promise.all(linkGroup.links.map((link) => {
return axios.get(link.url) return axios.get(link.url)
.then((response) => { .then((response) => {
return { return {
@ -210,7 +215,7 @@ END:VEVENT
} }
// Schedule a cron job to update the merged calendar every hour // Schedule a cron job to update the merged calendar every hour
cron.schedule('*/1 * * * *', () => { cron.schedule('*/3 * * * *', () => {
console.log('Updating merged calendar...'); console.log('Updating merged calendar...');
updateMergedCalendar(); updateMergedCalendar();
}); });