Compare commits
No commits in common. "0e58a4e12cdf4a6fbbc3338773c14e2d8971277e" and "5a5fcaeeaca972cb0a797e2b1c3e5a13ae035f07" have entirely different histories.
0e58a4e12c
...
5a5fcaeeac
13
script.js
13
script.js
|
@ -40,16 +40,5 @@ const form = document.getElementById('merge-form');
|
||||||
result.innerHTML = 'Error merging calendars';
|
result.innerHTML = 'Error merging calendars';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const refreshInterval = 60 * 60 * 1000; // 1 hour
|
|
||||||
setInterval(() => {
|
|
||||||
fetch('/merge')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
result.innerHTML = `Merged calendar URL: <a href="${data.url}">${data.url}</a>`;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
result.innerHTML = 'Error merging calendars';
|
|
||||||
});
|
|
||||||
}, refreshInterval);
|
|
||||||
|
|
50
server.js
50
server.js
|
@ -114,62 +114,14 @@ async function updateMergedCalendar(){
|
||||||
});
|
});
|
||||||
|
|
||||||
const results = await Promise.all(promises);
|
const results = await Promise.all(promises);
|
||||||
// Filter out any failed requests
|
|
||||||
const validResults = results.filter((result) => result !== null);
|
|
||||||
|
|
||||||
// Parse calendar data
|
|
||||||
const mergedCal = [];
|
|
||||||
validResults.forEach((result) => {
|
|
||||||
const calendar = ical.parseICS(result.data);
|
|
||||||
Object.keys(calendar).forEach((key) => {
|
|
||||||
const event = calendar[key];
|
|
||||||
mergedCal.push({
|
|
||||||
start: event.start,
|
|
||||||
end: event.end,
|
|
||||||
summary: `${result.prefix} ${event.summary}`,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save merged calendar to file
|
|
||||||
const filename = `merged-${Date.now()}.ics`;
|
|
||||||
let icalString = `BEGIN:VCALENDAR
|
|
||||||
VERSION:2.0
|
|
||||||
CALSCALE:GREGORIAN
|
|
||||||
METHOD:PUBLISH
|
|
||||||
BEGIN:VEVENT
|
|
||||||
`;
|
|
||||||
mergedCal.forEach((event) => {
|
|
||||||
icalString += `DTSTART:${event.start}
|
|
||||||
DTEND:${event.end}
|
|
||||||
SUMMARY:${event.summary}
|
|
||||||
END:VEVENT
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
icalString += `END:VCALENDAR`;
|
|
||||||
fs.writeFileSync(filename, icalString);
|
|
||||||
|
|
||||||
// Generate a unique URL for the merged calendar
|
|
||||||
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
|
|
||||||
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshInterval = 60 * 60 * 1000; // 1 hour
|
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
// Fetch new calendar data and update the merged calendar
|
|
||||||
updateMergedCalendar();
|
|
||||||
}, refreshInterval);
|
|
||||||
|
|
||||||
// Schedule a cron job to update the merged calendar every hour
|
// Schedule a cron job to update the merged calendar every hour
|
||||||
cron.schedule('0 * * * *', () => {
|
cron.schedule('0 * * * *', () => {
|
||||||
console.log('Updating merged calendar...');
|
console.log('Updating merged calendar...');
|
||||||
updateMergedCalendar();
|
// TO DO: implement the logic to update the merged calendar
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
|
|
Loading…
Reference in New Issue