From ea7e224c9e9697e9a2128ec17a978df792bbc271 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 4 Feb 2024 12:56:26 +0200 Subject: [PATCH] ran tsc locally --- dist/GameSource.js | 90 ++++++++++++++++++++++++---------------------- src/GameSource.ts | 2 +- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/dist/GameSource.js b/dist/GameSource.js index 92bd9e1..3f80ee8 100644 --- a/dist/GameSource.js +++ b/dist/GameSource.js @@ -12,49 +12,55 @@ const moment_1 = __importDefault(require("moment")); // require class GameSource { async getGamesFromHaifa() { 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"); - const games = []; - for (let gameBox of gameBoxs) { - const teamsPlaying = gameBox - .querySelectorAll(".team-name") - .map((team) => team.text); - const regex = /[\r\n\s]+/g; - const gameHeader = gameBox - .querySelector(".game-header") - .text.replace(regex, " ") - .trim(); - const headerSplit = gameHeader.split(","); - // 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); - 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") - .toISOString(); - games.push({ - summary: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`, - location: headerSplit[headerSplit.length - 1].trim(), - description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`, - start: { - dateTime: start, - timeZone: "Asia/Jerusalem", - }, - end: { - dateTime: end, - timeZone: "Asia/Jerusalem", - }, - }); + console.log('Trying to get games from Haifa...'); + try { + 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"); + const games = []; + for (let gameBox of gameBoxs) { + const teamsPlaying = gameBox + .querySelectorAll(".team-name") + .map((team) => team.text); + const regex = /[\r\n\s]+/g; + const gameHeader = gameBox + .querySelector(".game-header") + .text.replace(regex, " ") + .trim(); + const headerSplit = gameHeader.split(","); + // 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); + 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") + .toISOString(); + games.push({ + summary: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`, + location: headerSplit[headerSplit.length - 1].trim(), + description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`, + start: { + dateTime: start, + timeZone: "Asia/Jerusalem", + }, + end: { + dateTime: end, + timeZone: "Asia/Jerusalem", + }, + }); + } + // return []; + return games; + } + catch (error) { + console.error(error); } - // return []; - return games; } findTime(headerSplit) { let time = ''; diff --git a/src/GameSource.ts b/src/GameSource.ts index 535e144..93dec07 100644 --- a/src/GameSource.ts +++ b/src/GameSource.ts @@ -9,7 +9,7 @@ import moment from "moment"; // require export default class GameSource { async getGamesFromHaifa(): Promise { - const sourceUrl = `https://mhaifafc.com/games?lang=en`; + const sourceUrl = `http://mhaifafc.com/games?lang=en`; console.log('Trying to get games from Haifa...'); try { const result = await axios.get(sourceUrl);