2023-08-06 08:25:52 +00:00
|
|
|
"use strict";
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const GameSource_1 = __importDefault(require("./GameSource"));
|
|
|
|
const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar"));
|
|
|
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
|
dotenv_1.default.config();
|
|
|
|
class App {
|
|
|
|
constructor() {
|
|
|
|
this.gameSource = new GameSource_1.default();
|
|
|
|
this.googleCalendar = new GoogleCalendar_1.default();
|
|
|
|
}
|
|
|
|
async startCronJob() {
|
|
|
|
console.log("START CRON JOB");
|
|
|
|
const newGamesAdded = [];
|
|
|
|
await this.googleCalendar.init();
|
|
|
|
try {
|
|
|
|
const games = await app.gameSource.getGamesFromHaifa();
|
|
|
|
for (const game of games) {
|
|
|
|
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary);
|
2024-01-23 09:53:52 +00:00
|
|
|
console.log(game);
|
2023-08-06 08:25:52 +00:00
|
|
|
if (!isDuplicateEvent) {
|
|
|
|
newGamesAdded.push(game);
|
|
|
|
console.log("Event does not exist");
|
|
|
|
await this.googleCalendar.updateNewEvent([game]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("Event already exists");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newGamesAdded.length > 0) {
|
|
|
|
console.log("New games added:", newGamesAdded);
|
|
|
|
}
|
|
|
|
else {
|
2024-01-23 09:53:52 +00:00
|
|
|
console.log("No new games was Added!");
|
2023-08-06 08:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.error("Error in cron job:", error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const app = new App();
|
|
|
|
app.startCronJob().catch((error) => {
|
|
|
|
console.error("Error in app:", error.message);
|
|
|
|
});
|
|
|
|
// app.startWebServer();
|