logs added
This commit is contained in:
parent
15932a0c9d
commit
d3460f8871
4 changed files with 16 additions and 13 deletions
12
dist/GameSource.js
vendored
12
dist/GameSource.js
vendored
|
@ -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) {
|
||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
|
@ -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);
|
||||
|
|
|
@ -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<GoogleCalendarEvent[]> {
|
||||
async getGamesFromHaifa(logger: Function): Promise<GoogleCalendarEvent[]> {
|
||||
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);
|
||||
|
@ -45,12 +47,12 @@ export default class GameSource {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue