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 .env
config/client_google_auth.json config/client_google_auth.json
## Docker ##
build_image.sh
push_dockerhub.sh
## output ## ## output ##
dist dist

26
package-lock.json generated
View file

@ -10,6 +10,7 @@
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"express": "^4.18.2", "express": "^4.18.2",
"googleapis": "^113.0.0", "googleapis": "^113.0.0",
"ical": "^0.8.0",
"ics": "^3.1.0", "ics": "^3.1.0",
"moment": "^2.29.4", "moment": "^2.29.4",
"node-html-parser": "^6.1.5" "node-html-parser": "^6.1.5"
@ -823,6 +824,14 @@
"node": ">= 6" "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": { "node_modules/iconv-lite": {
"version": "0.4.24", "version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "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", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" "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": { "node_modules/safe-buffer": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",

View file

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

View file

@ -40,4 +40,9 @@ export default class Ics {
}; };
return icsEvent; 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(); const games = await this.gameSource.getGamesFromHaifa();
this.googleCalendar.updateNewEvent(games); this.googleCalendar.updateNewEvent(games);
} }
}
const app = new App();
console.log("Declaring Cron Job every day at 10:00")
async startCronJob() {
console.log("START CRON JOB")
const CronJob = require('cron').CronJob; const CronJob = require('cron').CronJob;
const job = new CronJob( const job = new CronJob(
"0 10 * * *", // every day at 10:00, "* * * * *", // every day at 10:00,
async () => { async () => {
console.log("Staring a new job") console.log("Staring a new job")
const outputFileLocation = 'public/maccabi-haifa-fc.ics'; const outputFileLocation = 'public/maccabi-haifa-fc.ics';
@ -48,13 +45,23 @@ const job = new CronJob(
const icsEvents = app.ics.generateIcsOutputFromGames(games); const icsEvents = app.ics.generateIcsOutputFromGames(games);
console.log("Writing ICS file to " + outputFileLocation) console.log("Writing ICS file to " + outputFileLocation)
fs.writeFileSync(outputFileLocation, icsEvents); 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, null,
true, true,
'Asia/Jerusalem' 'Asia/Jerusalem'
); );
}
async startWebServer() {
const webServer = express(); const webServer = express();
webServer.use(express.static('public')) webServer.use(express.static('public'))
@ -65,3 +72,14 @@ webServer.listen(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...") res.status(404).send("This is not the page you are looking for...")
}) })
}
}
const app = new App();
app.startCronJob();
app.startWebServer();