Compare commits
3 commits
52c8516a1e
...
b90d9524ff
Author | SHA1 | Date | |
---|---|---|---|
|
b90d9524ff | ||
|
54aec5450f | ||
|
332f363efc |
5 changed files with 82 additions and 28 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -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
26
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
32
src/index.ts
32
src/index.ts
|
@ -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")
|
||||
|
||||
async startCronJob() {
|
||||
console.log("START CRON JOB")
|
||||
const CronJob = require('cron').CronJob;
|
||||
|
||||
const job = new CronJob(
|
||||
"0 10 * * *", // every day at 10:00,
|
||||
"* * * * *", // every day at 10:00,
|
||||
async () => {
|
||||
console.log("Staring a new job")
|
||||
const outputFileLocation = 'public/maccabi-haifa-fc.ics';
|
||||
|
@ -48,13 +45,23 @@ 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'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
async startWebServer() {
|
||||
const webServer = express();
|
||||
webServer.use(express.static('public'))
|
||||
|
||||
|
@ -65,3 +72,14 @@ webServer.listen(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();
|
||||
|
||||
|
||||
app.startCronJob();
|
||||
app.startWebServer();
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue