Compare commits

...

3 commits

Author SHA1 Message Date
Kfir Dayan
b90d9524ff creating ical file as well 2023-04-04 12:31:20 +03:00
Kfir Dayan
54aec5450f install ical 2023-04-04 11:41:17 +03:00
Kfir Dayan
332f363efc added bash script for build and push 2023-04-03 20:09:44 +03:00
5 changed files with 82 additions and 28 deletions

4
.gitignore vendored
View file

@ -13,5 +13,9 @@ tmp
.env
config/client_google_auth.json
## Docker ##
build_image.sh
push_dockerhub.sh
## output ##
dist

26
package-lock.json generated
View file

@ -10,6 +10,7 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"googleapis": "^113.0.0",
"ical": "^0.8.0",
"ics": "^3.1.0",
"moment": "^2.29.4",
"node-html-parser": "^6.1.5"
@ -823,6 +824,14 @@
"node": ">= 6"
}
},
"node_modules/ical": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/ical/-/ical-0.8.0.tgz",
"integrity": "sha512-/viUSb/RGLLnlgm0lWRlPBtVeQguQRErSPYl3ugnUaKUnzQswKqOG3M8/P1v1AB5NJwlHTuvTq1cs4mpeG2rCg==",
"dependencies": {
"rrule": "2.4.1"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -1159,6 +1168,23 @@
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
},
"node_modules/rrule": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/rrule/-/rrule-2.4.1.tgz",
"integrity": "sha512-+NcvhETefswZq13T8nkuEnnQ6YgUeZaqMqVbp+ZiFDPCbp3AVgQIwUvNVDdMNrP05bKZG9ddDULFp0qZZYDrxg==",
"optionalDependencies": {
"luxon": "^1.3.3"
}
},
"node_modules/rrule/node_modules/luxon": {
"version": "1.28.1",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.28.1.tgz",
"integrity": "sha512-gYHAa180mKrNIUJCbwpmD0aTu9kV0dREDrwNnuyFAsO1Wt0EVYSZelPnJlbj9HplzXX/YWXHFTL45kvZ53M0pw==",
"optional": true,
"engines": {
"node": "*"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",

View file

@ -5,6 +5,7 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"googleapis": "^113.0.0",
"ical": "^0.8.0",
"ics": "^3.1.0",
"moment": "^2.29.4",
"node-html-parser": "^6.1.5"

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

@ -17,7 +17,7 @@ class App {
this.googleCalendar = new GoogleCalendar();
this.gameSource = new GameSource();
this.ics = new Ics();
}
async init() {
@ -30,38 +30,56 @@ class App {
const games = await this.gameSource.getGamesFromHaifa();
this.googleCalendar.updateNewEvent(games);
}
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';
console.log("Getting games from Haifa")
const games = await app.gameSource.getGamesFromHaifa();
console.log("Generating ICS file")
const icsEvents = app.ics.generateIcsOutputFromGames(games);
console.log("Writing ICS file to " + outputFileLocation)
fs.writeFileSync(outputFileLocation, icsEvents);
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'
);
}
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) {
res.status(404).send("This is not the page you are looking for...")
})
}
}
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 () => {
console.log("Staring a new job")
const outputFileLocation = 'public/maccabi-haifa-fc.ics';
console.log("Getting games from Haifa")
const games = await app.gameSource.getGamesFromHaifa();
console.log("Generating ICS file")
const icsEvents = app.ics.generateIcsOutputFromGames(games);
console.log("Writing ICS file to " + outputFileLocation)
fs.writeFileSync(outputFileLocation, icsEvents);
console.log("Done")
},
null,
true,
'Asia/Jerusalem'
);
app.startCronJob();
app.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) {
res.status(404).send("This is not the page you are looking for...")
})