diff --git a/dist/GameSource.js b/dist/GameSource.js index 125e331..c6deb32 100644 --- a/dist/GameSource.js +++ b/dist/GameSource.js @@ -10,7 +10,7 @@ const moment_1 = __importDefault(require("moment")); // require // This calss will be the game source. // search for upcomming games class GameSource { - async getGamesFromHaifa() { + async getGamesFromHaifa(logger) { const sourceUrl = `https://mhaifafc.com/games?lang=en`; console.log('Trying to get games from Haifa...'); try { @@ -41,12 +41,12 @@ class GameSource { // In data, if there is no time, it means it's the last game for the calender const lastGameForCalender = headerSplit.length < 4; const location = headerSplit[headerSplit.length - 1].trim(); - if (location === 'נדחה') - continue; - if (lastGameForCalender) - break; const gameDate = this.findDate(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 end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm") .add(2, "hours") @@ -65,7 +65,6 @@ class GameSource { }, }); } - // return []; return games; } catch (error) { @@ -91,6 +90,7 @@ class GameSource { return; } }); + // console.log("Cheking date: ", date, "By split: ", headerSplit) return date.trim(); } getOpponentIndexByStadium(stadium) { diff --git a/dist/index.js b/dist/index.js index 3871a8d..9baf05c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -20,7 +20,7 @@ class App { const newGamesAdded = []; await this.googleCalendar.init(); try { - const games = await this.gameSource.getGamesFromHaifa(); + const games = await this.gameSource.getGamesFromHaifa(this.writeLog); for (const game of games) { const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(game.start.dateTime, game.end.dateTime, game.summary); console.log(game); diff --git a/src/GameSource.ts b/src/GameSource.ts index b7c9379..bcc0602 100644 --- a/src/GameSource.ts +++ b/src/GameSource.ts @@ -3,12 +3,13 @@ import axios from "axios"; import { GoogleCalendarEvent } from "./types"; import { parse } from "node-html-parser"; import moment from "moment"; // require +import fs from 'fs'; // Importing fs for logging // This calss will be the game source. // search for upcomming games export default class GameSource { - async getGamesFromHaifa(): Promise { + async getGamesFromHaifa(logger: Function): Promise { const sourceUrl = `https://mhaifafc.com/games?lang=en`; console.log('Trying to get games from Haifa...'); try { @@ -31,6 +32,7 @@ export default class GameSource { const games: GoogleCalendarEvent[] = []; for (let gameBox of gameBoxs) { + const teamsPlaying = gameBox .querySelectorAll(".team-name") .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 const lastGameForCalender = headerSplit.length < 4; const location = headerSplit[headerSplit.length - 1].trim(); - - if (location === 'נדחה') continue; - if (lastGameForCalender) break; const gameDate = this.findDate(headerSplit); const gameTime = this.findTime(headerSplit); + if (location === 'נדחה') continue; + if (lastGameForCalender && gameDate !== '') break; + const start = moment( gameDate + gameTime, "DD/MM/YYYYHH:mm" @@ -73,7 +75,6 @@ export default class GameSource { }, }); } - // return []; return games; } catch (error) { @@ -100,6 +101,8 @@ export default class GameSource { return; } }) + + // console.log("Cheking date: ", date, "By split: ", headerSplit) return date.trim(); } diff --git a/src/index.ts b/src/index.ts index 933e81d..0b70064 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ class App { const newGamesAdded = []; await this.googleCalendar.init(); try { - const games = await this.gameSource.getGamesFromHaifa(); + const games = await this.gameSource.getGamesFromHaifa(this.writeLog); for (const game of games) { const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent(