Compare commits
No commits in common. "b90d9524ff4a85cedfd15e3e860396ef597ef494" and "52c8516a1e3a8120b745f58dff99339dfd4a7be8" have entirely different histories.
b90d9524ff
...
52c8516a1e
5 changed files with 28 additions and 82 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -13,9 +13,5 @@ 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
26
package-lock.json
generated
|
@ -10,7 +10,6 @@
|
||||||
"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"
|
||||||
|
@ -824,14 +823,6 @@
|
||||||
"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",
|
||||||
|
@ -1168,23 +1159,6 @@
|
||||||
"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",
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
"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"
|
||||||
|
|
|
@ -40,9 +40,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
74
src/index.ts
74
src/index.ts
|
@ -17,7 +17,7 @@ class App {
|
||||||
this.googleCalendar = new GoogleCalendar();
|
this.googleCalendar = new GoogleCalendar();
|
||||||
this.gameSource = new GameSource();
|
this.gameSource = new GameSource();
|
||||||
this.ics = new Ics();
|
this.ics = new Ics();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
@ -30,56 +30,38 @@ class App {
|
||||||
const games = await this.gameSource.getGamesFromHaifa();
|
const games = await this.gameSource.getGamesFromHaifa();
|
||||||
this.googleCalendar.updateNewEvent(games);
|
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();
|
const app = new App();
|
||||||
|
console.log("Declaring Cron Job every day at 10:00")
|
||||||
|
|
||||||
|
const CronJob = require('cron').CronJob;
|
||||||
|
|
||||||
app.startCronJob();
|
const job = new CronJob(
|
||||||
app.startWebServer();
|
"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'
|
||||||
|
);
|
||||||
|
|
||||||
|
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...")
|
||||||
|
})
|
Loading…
Reference in a new issue