haifa-reminder/dist/index.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-07-26 11:02:08 +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");
await this.googleCalendar.init();
// Schedule the job to run daily at a specific time (e.g., 1:00 AM)
2023-07-26 12:14:58 +00:00
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);
if (!isDuplicateEvent) {
console.log("Event does not exist");
await this.googleCalendar.updateNewEvent([game]);
}
else {
console.log("Event already exists");
2023-07-26 11:02:08 +00:00
}
}
2023-07-26 12:14:58 +00:00
}
catch (error) {
console.error("Error in cron job:", error.message);
}
2023-07-26 11:02:08 +00:00
}
}
const app = new App();
2023-07-26 11:31:24 +00:00
app.startCronJob().catch((error) => {
console.error("Error in app:", error.message);
});
2023-07-26 11:02:08 +00:00
// app.startWebServer();