creating ical file as well

This commit is contained in:
Kfir Dayan 2023-04-04 12:31:20 +03:00
parent 54aec5450f
commit b90d9524ff
2 changed files with 51 additions and 28 deletions

View file

@ -40,4 +40,9 @@ export default class Ics {
};
return icsEvent;
}
convertIcsToIcal = (icsEvents: string) => {
const icalEvents = icsEvents.replace(/BEGIN:VEVENT/g, 'BEGIN:VEVENT\r\nUID:' + uuid);
return icalEvents;
}
}

View file

@ -30,15 +30,12 @@ class App {
const games = await this.gameSource.getGamesFromHaifa();
this.googleCalendar.updateNewEvent(games);
}
}
const app = new App();
console.log("Declaring Cron Job every day at 10:00")
const CronJob = require('cron').CronJob;
const job = new CronJob(
"0 10 * * *", // every day at 10:00,
async startCronJob() {
console.log("START CRON JOB")
const CronJob = require('cron').CronJob;
const job = new CronJob(
"* * * * *", // every day at 10:00,
async () => {
console.log("Staring a new job")
const outputFileLocation = 'public/maccabi-haifa-fc.ics';
@ -48,20 +45,41 @@ const job = new CronJob(
const icsEvents = app.ics.generateIcsOutputFromGames(games);
console.log("Writing ICS file to " + outputFileLocation)
fs.writeFileSync(outputFileLocation, icsEvents);
console.log("Done")
console.log("Done Ics file")
console.log("converting ics file to ical file")
const outputIcalFileLocation = 'public/maccabi-haifa-fc.ical';
const icalEvents = app.ics.convertIcsToIcal(icsEvents);
console.log("Writing Ical file to " + outputIcalFileLocation)
fs.writeFileSync(outputIcalFileLocation, icalEvents);
},
null,
true,
'Asia/Jerusalem'
);
);
const webServer = express();
webServer.use(express.static('public'))
}
webServer.listen(process.env.PORT, () => {
async startWebServer() {
const webServer = express();
webServer.use(express.static('public'))
webServer.listen(process.env.PORT, () => {
console.log(`Calender app listening on port ${process.env.PORT}!`)
})
})
webServer.use(function (req, res, next) {
webServer.use(function (req, res, next) {
res.status(404).send("This is not the page you are looking for...")
})
})
}
}
const app = new App();
app.startCronJob();
app.startWebServer();