Compare commits
No commits in common. "f95ed86012ab62c0259f3dc25d7a4c2a6eaa98f3" and "43bb990df5aea39fd80fdab5479f29eab89623a7" have entirely different histories.
f95ed86012
...
43bb990df5
5 changed files with 23 additions and 22 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,9 +1,8 @@
|
||||||
## Node modules ##
|
## Node modules ##
|
||||||
node_modules
|
# node_modules
|
||||||
|
|
||||||
#javascript build files #
|
#javascript build files #
|
||||||
public/**/*
|
public/**/*
|
||||||
dist/**/*
|
|
||||||
|
|
||||||
# Tmp files #
|
# Tmp files #
|
||||||
tmp
|
tmp
|
||||||
|
@ -11,7 +10,6 @@ tmp
|
||||||
|
|
||||||
## ENV Vars ##
|
## ENV Vars ##
|
||||||
.env
|
.env
|
||||||
config/client_google_auth.json
|
|
||||||
|
|
||||||
## Docker ##
|
## Docker ##
|
||||||
build_image.sh
|
build_image.sh
|
||||||
|
|
2
dist/GameSource.js
vendored
2
dist/GameSource.js
vendored
|
@ -31,7 +31,7 @@ class GameSource {
|
||||||
const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").add(2, "hours").toISOString();
|
const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").add(2, "hours").toISOString();
|
||||||
games.push({
|
games.push({
|
||||||
summary: 'Maccabi Haifa F.C.',
|
summary: 'Maccabi Haifa F.C.',
|
||||||
location: headerSplit[4].trim(),
|
location: "Ofir's stadium",
|
||||||
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
||||||
start: {
|
start: {
|
||||||
dateTime: start,
|
dateTime: start,
|
||||||
|
|
31
dist/index.js
vendored
31
dist/index.js
vendored
|
@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const GameSource_1 = __importDefault(require("./GameSource"));
|
const GameSource_1 = __importDefault(require("./GameSource"));
|
||||||
const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar"));
|
const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar"));
|
||||||
const dotenv_1 = __importDefault(require("dotenv"));
|
const dotenv_1 = __importDefault(require("dotenv"));
|
||||||
|
const node_cron_1 = __importDefault(require("node-cron"));
|
||||||
dotenv_1.default.config();
|
dotenv_1.default.config();
|
||||||
class App {
|
class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -16,22 +17,24 @@ class App {
|
||||||
console.log("START CRON JOB");
|
console.log("START CRON JOB");
|
||||||
await this.googleCalendar.init();
|
await this.googleCalendar.init();
|
||||||
// Schedule the job to run daily at a specific time (e.g., 1:00 AM)
|
// Schedule the job to run daily at a specific time (e.g., 1:00 AM)
|
||||||
try {
|
node_cron_1.default.schedule("* * * * *", async () => {
|
||||||
const games = await app.gameSource.getGamesFromHaifa();
|
try {
|
||||||
for (const game of games) {
|
const games = await app.gameSource.getGamesFromHaifa();
|
||||||
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary);
|
for (const game of games) {
|
||||||
if (!isDuplicateEvent) {
|
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary);
|
||||||
console.log("Event does not exist");
|
if (!isDuplicateEvent) {
|
||||||
await this.googleCalendar.updateNewEvent([game]);
|
console.log("Event does not exist");
|
||||||
}
|
await this.googleCalendar.updateNewEvent([game]);
|
||||||
else {
|
}
|
||||||
console.log("Event already exists");
|
else {
|
||||||
|
console.log("Event already exists");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (error) {
|
||||||
catch (error) {
|
console.error("Error in cron job:", error.message);
|
||||||
console.error("Error in cron job:", error.message);
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const app = new App();
|
const app = new App();
|
||||||
|
|
|
@ -33,11 +33,9 @@ export default class GameSource {
|
||||||
const start = moment(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString();
|
const start = moment(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString();
|
||||||
const end = moment(gameDate + gameTime, "DD/MM/YYYYHH:mm").add(2, "hours").toISOString();
|
const end = moment(gameDate + gameTime, "DD/MM/YYYYHH:mm").add(2, "hours").toISOString();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
games.push({
|
games.push({
|
||||||
summary: 'Maccabi Haifa F.C.',
|
summary: 'Maccabi Haifa F.C.',
|
||||||
location: headerSplit[4].trim(),
|
location: "Ofir's stadium",
|
||||||
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
||||||
start: {
|
start: {
|
||||||
dateTime: start,
|
dateTime: start,
|
||||||
|
|
|
@ -21,6 +21,7 @@ class App {
|
||||||
await this.googleCalendar.init();
|
await this.googleCalendar.init();
|
||||||
|
|
||||||
// Schedule the job to run daily at a specific time (e.g., 1:00 AM)
|
// Schedule the job to run daily at a specific time (e.g., 1:00 AM)
|
||||||
|
cron.schedule("* * * * *", async () => {
|
||||||
try {
|
try {
|
||||||
const games = await app.gameSource.getGamesFromHaifa();
|
const games = await app.gameSource.getGamesFromHaifa();
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ class App {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in cron job:", error.message);
|
console.error("Error in cron job:", error.message);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue