logs added

This commit is contained in:
Kfir Dayan 2024-07-31 21:53:04 +03:00
parent 15932a0c9d
commit d3460f8871
4 changed files with 16 additions and 13 deletions

12
dist/GameSource.js vendored
View file

@ -10,7 +10,7 @@ const moment_1 = __importDefault(require("moment")); // require
// This calss will be the game source. // This calss will be the game source.
// search for upcomming games // search for upcomming games
class GameSource { class GameSource {
async getGamesFromHaifa() { async getGamesFromHaifa(logger) {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `https://mhaifafc.com/games?lang=en`;
console.log('Trying to get games from Haifa...'); console.log('Trying to get games from Haifa...');
try { try {
@ -41,12 +41,12 @@ class GameSource {
// In data, if there is no time, it means it's the last game for the calender // In data, if there is no time, it means it's the last game for the calender
const lastGameForCalender = headerSplit.length < 4; const lastGameForCalender = headerSplit.length < 4;
const location = headerSplit[headerSplit.length - 1].trim(); const location = headerSplit[headerSplit.length - 1].trim();
if (location === 'נדחה')
continue;
if (lastGameForCalender)
break;
const gameDate = this.findDate(headerSplit); const gameDate = this.findDate(headerSplit);
const gameTime = this.findTime(headerSplit); const gameTime = this.findTime(headerSplit);
if (location === 'נדחה')
continue;
if (lastGameForCalender && gameDate !== '')
break;
const start = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString(); const start = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString();
const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm") const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm")
.add(2, "hours") .add(2, "hours")
@ -65,7 +65,6 @@ class GameSource {
}, },
}); });
} }
// return [];
return games; return games;
} }
catch (error) { catch (error) {
@ -91,6 +90,7 @@ class GameSource {
return; return;
} }
}); });
// console.log("Cheking date: ", date, "By split: ", headerSplit)
return date.trim(); return date.trim();
} }
getOpponentIndexByStadium(stadium) { getOpponentIndexByStadium(stadium) {

2
dist/index.js vendored
View file

@ -20,7 +20,7 @@ class App {
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
const games = await this.gameSource.getGamesFromHaifa(); const games = await this.gameSource.getGamesFromHaifa(this.writeLog);
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);

View file

@ -3,12 +3,13 @@ import axios from "axios";
import { GoogleCalendarEvent } from "./types"; import { GoogleCalendarEvent } from "./types";
import { parse } from "node-html-parser"; import { parse } from "node-html-parser";
import moment from "moment"; // require import moment from "moment"; // require
import fs from 'fs'; // Importing fs for logging
// This calss will be the game source. // This calss will be the game source.
// search for upcomming games // search for upcomming games
export default class GameSource { export default class GameSource {
async getGamesFromHaifa(): Promise<GoogleCalendarEvent[]> { async getGamesFromHaifa(logger: Function): Promise<GoogleCalendarEvent[]> {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `https://mhaifafc.com/games?lang=en`;
console.log('Trying to get games from Haifa...'); console.log('Trying to get games from Haifa...');
try { try {
@ -31,6 +32,7 @@ export default class GameSource {
const games: GoogleCalendarEvent[] = []; const games: GoogleCalendarEvent[] = [];
for (let gameBox of gameBoxs) { for (let gameBox of gameBoxs) {
const teamsPlaying = gameBox const teamsPlaying = gameBox
.querySelectorAll(".team-name") .querySelectorAll(".team-name")
.map((team: any) => team.text); .map((team: any) => team.text);
@ -44,13 +46,13 @@ export default class GameSource {
// In data, if there is no time, it means it's the last game for the calender // In data, if there is no time, it means it's the last game for the calender
const lastGameForCalender = headerSplit.length < 4; const lastGameForCalender = headerSplit.length < 4;
const location = headerSplit[headerSplit.length - 1].trim(); const location = headerSplit[headerSplit.length - 1].trim();
if (location === 'נדחה') continue;
if (lastGameForCalender) break;
const gameDate = this.findDate(headerSplit); const gameDate = this.findDate(headerSplit);
const gameTime = this.findTime(headerSplit); const gameTime = this.findTime(headerSplit);
if (location === 'נדחה') continue;
if (lastGameForCalender && gameDate !== '') break;
const start = moment( const start = moment(
gameDate + gameTime, gameDate + gameTime,
"DD/MM/YYYYHH:mm" "DD/MM/YYYYHH:mm"
@ -73,7 +75,6 @@ export default class GameSource {
}, },
}); });
} }
// return [];
return games; return games;
} }
catch (error) { catch (error) {
@ -100,6 +101,8 @@ export default class GameSource {
return; return;
} }
}) })
// console.log("Cheking date: ", date, "By split: ", headerSplit)
return date.trim(); return date.trim();
} }

View file

@ -22,7 +22,7 @@ class App {
const newGamesAdded = []; const newGamesAdded = [];
await this.googleCalendar.init(); await this.googleCalendar.init();
try { try {
const games = await this.gameSource.getGamesFromHaifa(); const games = await this.gameSource.getGamesFromHaifa(this.writeLog);
for (const game of games) { for (const game of games) {
const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent( const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(