forked from ryanmwangi/CalMerger
fetch calendar data from urls
This commit is contained in:
parent
4fd447104b
commit
5a5fcaeeac
31
server.js
31
server.js
|
@ -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}`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue