Compare commits

...

3 Commits

2 changed files with 14 additions and 3 deletions

0
merged_calendar_url.txt Normal file
View File

View File

@ -109,7 +109,7 @@ async function updateMergedCalendar(){
// Load calendars data from file
const calendarsFile = 'calendars.json';
const calendars = JSON.parse(fs.readFileSync(calendarsFile, 'utf8'));
// Fetch calendar data from URLs
const promises = calendars.map((calendar) => {
return axios.get(calendar.url)
@ -168,10 +168,15 @@ END:VEVENT
`;
});
icalString += `END:VCALENDAR`;
fs.writeFileSync(filename, icalString);
// Generate a unique URL for the merged calendar
const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/${filename}`;
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
// Store the merged calendar URL in a file
fs.writeFileSync(mergedCalendarUrlFile, mergedCalendarUrl);
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
@ -180,13 +185,19 @@ END:VEVENT
}
}
// Schedule a cron job to update the merged calendar every hour
cron.schedule('0 * * * *', () => {
console.log('Updating merged calendar...');
updateMergedCalendar();
});
// serve updated merged calendar to user
app.get('/merged-calendar', (req, res) => {
const mergedCalendarUrlFile = 'merged_calendar_url.txt';
const mergedCalendarUrl = fs.readFileSync(mergedCalendarUrlFile, 'utf8');
res.redirect(mergedCalendarUrl);
});
// Start the server
const port = 3000;
app.listen(port, () => {