fetch calendar data from urls

This commit is contained in:
Ryan Mwangi 2024-10-02 15:21:00 +03:00
parent 4fd447104b
commit 5a5fcaeeac
1 changed files with 25 additions and 6 deletions

View File

@ -91,18 +91,31 @@ app.get('/:filename', (req, res) => {
res.sendFile(filename, { root: '.' });
});
// Start the server
const port = 3000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
// Function to update the merged calendar
async function updateMergedCalendar(){
try {
// 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)
.then((response) => {
return {
data: response.data,
prefix: calendar.prefix,
};
})
.catch((error) => {
console.error(error);
return null;
});
});
const results = await Promise.all(promises);
} catch (error) {
console.error(error);
}
}
// Schedule a cron job to update the merged calendar every hour
@ -110,3 +123,9 @@ cron.schedule('0 * * * *', () => {
console.log('Updating merged calendar...');
// TO DO: implement the logic to update the merged calendar
});
// Start the server
const port = 3000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});