remove https
This commit is contained in:
parent
daea0c9cfb
commit
dbdf76554b
5 changed files with 39 additions and 10 deletions
6
cron.log
Normal file
6
cron.log
Normal 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
2
dist/GameSource.js
vendored
|
@ -11,7 +11,7 @@ const moment_1 = __importDefault(require("moment")); // require
|
|||
// search for upcomming games
|
||||
class GameSource {
|
||||
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 parsedResult = (0, node_html_parser_1.parse)(result.data.toString());
|
||||
const gameBoxs = parsedResult.querySelectorAll(".game-box");
|
||||
|
|
18
dist/index.js
vendored
18
dist/index.js
vendored
|
@ -7,6 +7,7 @@ const GameSource_1 = __importDefault(require("./GameSource"));
|
|||
const GoogleCalendar_1 = __importDefault(require("./GoogleCalendar"));
|
||||
const dotenv_1 = __importDefault(require("dotenv"));
|
||||
const node_cron_1 = __importDefault(require("node-cron"));
|
||||
const fs_1 = __importDefault(require("fs")); // Importing fs for logging
|
||||
dotenv_1.default.config();
|
||||
class App {
|
||||
constructor() {
|
||||
|
@ -14,11 +15,12 @@ class App {
|
|||
this.googleCalendar = new GoogleCalendar_1.default();
|
||||
}
|
||||
async startCronJob() {
|
||||
this.writeLog('START CRON JOB'); // Log when the cron job starts
|
||||
console.log("START Haifa Reminder");
|
||||
const newGamesAdded = [];
|
||||
await this.googleCalendar.init();
|
||||
try {
|
||||
const games = await app.gameSource.getGamesFromHaifa();
|
||||
const games = await this.gameSource.getGamesFromHaifa();
|
||||
for (const game of games) {
|
||||
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary);
|
||||
console.log(game);
|
||||
|
@ -35,20 +37,30 @@ class App {
|
|||
console.log("New games added:", newGamesAdded);
|
||||
}
|
||||
else {
|
||||
console.log("No new games was Added!");
|
||||
console.log("No new games were Added!");
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
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();
|
||||
node_cron_1.default.schedule('* * * * *', () => {
|
||||
console.log('Running startCronJob at 7:00 AM Jerusalem time');
|
||||
console.log("START CRON JOB");
|
||||
app.startCronJob().catch((error) => {
|
||||
console.error("Error in scheduled cron job:", error.message);
|
||||
app.writeLog(`ERROR: ${error.message}`); // Log any errors
|
||||
});
|
||||
}, {
|
||||
scheduled: true,
|
||||
|
|
|
@ -9,7 +9,7 @@ import moment from "moment"; // require
|
|||
|
||||
export default class GameSource {
|
||||
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 parsedResult = parse(result.data.toString());
|
||||
const gameBoxs = parsedResult.querySelectorAll(".game-box");
|
||||
|
|
19
src/index.ts
19
src/index.ts
|
@ -2,6 +2,7 @@ import GameSource from "./GameSource";
|
|||
import GoogleCalendar from "./GoogleCalendar";
|
||||
import env from "dotenv";
|
||||
import cron from 'node-cron';
|
||||
import fs from 'fs'; // Importing fs for logging
|
||||
|
||||
env.config();
|
||||
|
||||
|
@ -16,11 +17,12 @@ class App {
|
|||
}
|
||||
|
||||
async startCronJob() {
|
||||
this.writeLog('START CRON JOB'); // Log when the cron job starts
|
||||
console.log("START Haifa Reminder");
|
||||
const newGamesAdded = [];
|
||||
await this.googleCalendar.init();
|
||||
try {
|
||||
const games = await app.gameSource.getGamesFromHaifa();
|
||||
const games = await this.gameSource.getGamesFromHaifa();
|
||||
|
||||
for (const game of games) {
|
||||
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(
|
||||
|
@ -41,22 +43,31 @@ class App {
|
|||
if (newGamesAdded.length > 0) {
|
||||
console.log("New games added:", newGamesAdded);
|
||||
} else {
|
||||
console.log("No new games was Added!");
|
||||
console.log("No new games were Added!");
|
||||
}
|
||||
} catch (error) {
|
||||
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();
|
||||
|
||||
|
||||
cron.schedule('* * * * *', () => {
|
||||
console.log('Running startCronJob at 7:00 AM Jerusalem time');
|
||||
console.log("START CRON JOB");
|
||||
app.startCronJob().catch((error) => {
|
||||
console.error("Error in scheduled cron job:", error.message);
|
||||
app.writeLog(`ERROR: ${error.message}`); // Log any errors
|
||||
});
|
||||
}, {
|
||||
scheduled: true,
|
||||
|
|
Loading…
Reference in a new issue