forked from ryanmwangi/CalMerger
edit updateMergedCalendar function and update cron to run every minute for testing
This commit is contained in:
parent
00a7d97b21
commit
4cac613470
14
server.js
14
server.js
|
@ -130,17 +130,17 @@ async function updateMergedCalendar(){
|
||||||
try {
|
try {
|
||||||
// Load calendars data from calendars.json file
|
// Load calendars data from calendars.json file
|
||||||
const calendarsFile = 'calendars.json';
|
const calendarsFile = 'calendars.json';
|
||||||
const calendars = JSON.parse(fs.readFileSync(calendarsFile, 'utf8'));
|
const calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8'));
|
||||||
|
|
||||||
// Fetch calendar data for each link group
|
// Fetch calendar data for each link group
|
||||||
const promises = calendarsData.linkGroups.map((linkGroup) => {
|
const promises = calendarsData.calendars.map((calendar) => {
|
||||||
return Promise.all(linkGroup.links.map((link) => {
|
return Promise.all(calendar.links.map((link) => {
|
||||||
return axios.get(link.url)
|
return axios.get(link.url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return {
|
return {
|
||||||
data: response.data,
|
data: response.data,
|
||||||
prefix: link.prefix,
|
prefix: link.prefix,
|
||||||
override: link.overrideSummary,
|
override: link.override,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -185,8 +185,8 @@ METHOD:PUBLISH
|
||||||
`;
|
`;
|
||||||
mergedCal.forEach((event) => {
|
mergedCal.forEach((event) => {
|
||||||
icalString += `BEGIN:VEVENT
|
icalString += `BEGIN:VEVENT
|
||||||
DTSTART:${event.start}
|
DTSTART;VALUE=DATE:${event.start.toISOString().split('T')[0].replace(/-/g, '')}
|
||||||
DTEND:${event.end}
|
DTEND;VALUE=DATE:${event.end.toISOString().split('T')[0].replace(/-/g, '')}
|
||||||
SUMMARY:${event.summary}
|
SUMMARY:${event.summary}
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
`;
|
`;
|
||||||
|
@ -210,7 +210,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('0 * * * *', () => {
|
cron.schedule('*/1 * * * *', () => {
|
||||||
console.log('Updating merged calendar...');
|
console.log('Updating merged calendar...');
|
||||||
updateMergedCalendar();
|
updateMergedCalendar();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue