remove https

This commit is contained in:
Kfir Dayan 2024-02-04 12:52:15 +02:00
parent daea0c9cfb
commit dbdf76554b
5 changed files with 39 additions and 10 deletions

6
cron.log Normal file
View file

@ -0,0 +1,6 @@
2024-02-04T10:30:00.949Z - START CRON JOB
2024-02-04T10:30:03.875Z - END CRON JOB
2024-02-04T10:31:00.105Z - START CRON JOB
2024-02-04T10:31:00.825Z - END CRON JOB
2024-02-04T10:52:00.163Z - START CRON JOB
2024-02-04T10:52:03.334Z - END CRON JOB

2
dist/GameSource.js vendored
View file

@ -11,7 +11,7 @@ const moment_1 = __importDefault(require("moment")); // require
// search for upcomming games // search for upcomming games
class GameSource { class GameSource {
async getGamesFromHaifa() { async getGamesFromHaifa() {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `http://mhaifafc.com/games?lang=en`;
const result = await axios_1.default.get(sourceUrl); const result = await axios_1.default.get(sourceUrl);
const parsedResult = (0, node_html_parser_1.parse)(result.data.toString()); const parsedResult = (0, node_html_parser_1.parse)(result.data.toString());
const gameBoxs = parsedResult.querySelectorAll(".game-box"); const gameBoxs = parsedResult.querySelectorAll(".game-box");

18
dist/index.js vendored
View file

@ -7,6 +7,7 @@ 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")); const node_cron_1 = __importDefault(require("node-cron"));
const fs_1 = __importDefault(require("fs")); // Importing fs for logging
dotenv_1.default.config(); dotenv_1.default.config();
class App { class App {
constructor() { constructor() {
@ -14,11 +15,12 @@ class App {
this.googleCalendar = new GoogleCalendar_1.default(); this.googleCalendar = new GoogleCalendar_1.default();
} }
async startCronJob() { async startCronJob() {
this.writeLog('START CRON JOB'); // Log when the cron job starts
console.log("START Haifa Reminder"); console.log("START Haifa Reminder");
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
const games = await app.gameSource.getGamesFromHaifa(); const games = await this.gameSource.getGamesFromHaifa();
for (const game of games) { for (const game of games) {
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary); const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary);
console.log(game); console.log(game);
@ -35,20 +37,30 @@ class App {
console.log("New games added:", newGamesAdded); console.log("New games added:", newGamesAdded);
} }
else { else {
console.log("No new games was Added!"); console.log("No new games were Added!");
} }
} }
catch (error) { catch (error) {
console.error("Error in cron job:", error.message); console.error("Error in cron job:", error.message);
} }
finally {
this.writeLog('END CRON JOB'); // Log when the cron job ends
}
}
writeLog(message) {
const timestamp = new Date().toISOString();
const logMessage = `${timestamp} - ${message}\n`;
// Write to log file synchronously
fs_1.default.appendFileSync('cron.log', logMessage);
console.log(logMessage); // Optional: also log to console
} }
} }
const app = new App(); const app = new App();
node_cron_1.default.schedule('* * * * *', () => { node_cron_1.default.schedule('* * * * *', () => {
console.log('Running startCronJob at 7:00 AM Jerusalem time'); console.log('Running startCronJob at 7:00 AM Jerusalem time');
console.log("START CRON JOB");
app.startCronJob().catch((error) => { app.startCronJob().catch((error) => {
console.error("Error in scheduled cron job:", error.message); console.error("Error in scheduled cron job:", error.message);
app.writeLog(`ERROR: ${error.message}`); // Log any errors
}); });
}, { }, {
scheduled: true, scheduled: true,

View file

@ -9,7 +9,7 @@ import moment from "moment"; // require
export default class GameSource { export default class GameSource {
async getGamesFromHaifa(): Promise<GoogleCalendarEvent[]> { async getGamesFromHaifa(): Promise<GoogleCalendarEvent[]> {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `http://mhaifafc.com/games?lang=en`;
const result = await axios.get(sourceUrl); const result = await axios.get(sourceUrl);
const parsedResult = parse(result.data.toString()); const parsedResult = parse(result.data.toString());
const gameBoxs = parsedResult.querySelectorAll(".game-box"); const gameBoxs = parsedResult.querySelectorAll(".game-box");

View file

@ -2,6 +2,7 @@ import GameSource from "./GameSource";
import GoogleCalendar from "./GoogleCalendar"; import GoogleCalendar from "./GoogleCalendar";
import env from "dotenv"; import env from "dotenv";
import cron from 'node-cron'; import cron from 'node-cron';
import fs from 'fs'; // Importing fs for logging
env.config(); env.config();
@ -16,11 +17,12 @@ class App {
} }
async startCronJob() { async startCronJob() {
this.writeLog('START CRON JOB'); // Log when the cron job starts
console.log("START Haifa Reminder"); console.log("START Haifa Reminder");
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
const games = await app.gameSource.getGamesFromHaifa(); const games = await this.gameSource.getGamesFromHaifa();
for (const game of games) { for (const game of games) {
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent( const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(
@ -41,22 +43,31 @@ class App {
if (newGamesAdded.length > 0) { if (newGamesAdded.length > 0) {
console.log("New games added:", newGamesAdded); console.log("New games added:", newGamesAdded);
} else { } else {
console.log("No new games was Added!"); console.log("No new games were Added!");
} }
} catch (error) { } catch (error) {
console.error("Error in cron job:", error.message); console.error("Error in cron job:", error.message);
} finally {
this.writeLog('END CRON JOB'); // Log when the cron job ends
} }
} }
writeLog(message) {
const timestamp = new Date().toISOString();
const logMessage = `${timestamp} - ${message}\n`;
// Write to log file synchronously
fs.appendFileSync('cron.log', logMessage);
console.log(logMessage); // Optional: also log to console
}
} }
const app = new App(); const app = new App();
cron.schedule('* * * * *', () => { cron.schedule('* * * * *', () => {
console.log('Running startCronJob at 7:00 AM Jerusalem time'); console.log('Running startCronJob at 7:00 AM Jerusalem time');
console.log("START CRON JOB");
app.startCronJob().catch((error) => { app.startCronJob().catch((error) => {
console.error("Error in scheduled cron job:", error.message); console.error("Error in scheduled cron job:", error.message);
app.writeLog(`ERROR: ${error.message}`); // Log any errors
}); });
}, { }, {
scheduled: true, scheduled: true,