1
0
Fork 0

update name of function used to updateMergedCalendars

This commit is contained in:
Ryan Mwangi 2024-10-19 17:41:06 +03:00
parent 42bfb3bdd2
commit 3901a5d894
1 changed files with 5 additions and 9 deletions

View File

@ -121,18 +121,14 @@ function saveCalendarData(calendarId, calendars) {
}); });
fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2)); fs.writeFileSync(CALENDARS_FILE, JSON.stringify(calendarsData, null, 2));
} }
// Function to update the merged calendar // Function to update the merged calendar
async function updateMergedCalendar(){ async function updateMergedCalendars(){
try { try {
// Load calendars data from calendars.json file // Load calendars data from calendars.json file
const calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8')); const calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8'));
// Check if calendarsData is defined and has the expected structure // Fetch calendar data for each merged calendar
if (!calendarsData || !calendarsData.linkGroups) {
throw new Error('Invalid calendars data structure');
}
// Fetch calendar data for each link group
for (const mergedCalendar of calendarsData.mergedCalendars) { for (const mergedCalendar of calendarsData.mergedCalendars) {
const promises = mergedCalendar.calendars.map((calendar) => { const promises = mergedCalendar.calendars.map((calendar) => {
return axios.get(calendar.url) return axios.get(calendar.url)
@ -193,7 +189,7 @@ END:VEVENT
icalString += `END:VCALENDAR`; icalString += `END:VCALENDAR`;
// Store the merged calendar URL in a file // Store the merged calendar URL in a file
fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString); fs.writeFileSync(`${MERGED_CALENDARS_DIR}/${filename}`, icalString);
console.log(`Merged calendar updated: ${mergedCalendarUrl}`); console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
@ -206,7 +202,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('*/3 * * * *', () => { cron.schedule('*/3 * * * *', () => {
console.log('Updating merged calendar...'); console.log('Updating merged calendar...');
updateMergedCalendar(); updateMergedCalendars();
}); });
// Start the server // Start the server