ran tsc locally
This commit is contained in:
parent
d5408c359b
commit
ea7e224c9e
2 changed files with 49 additions and 43 deletions
90
dist/GameSource.js
vendored
90
dist/GameSource.js
vendored
|
@ -12,49 +12,55 @@ const moment_1 = __importDefault(require("moment")); // require
|
||||||
class GameSource {
|
class GameSource {
|
||||||
async getGamesFromHaifa() {
|
async getGamesFromHaifa() {
|
||||||
const sourceUrl = `http://mhaifafc.com/games?lang=en`;
|
const sourceUrl = `http://mhaifafc.com/games?lang=en`;
|
||||||
const result = await axios_1.default.get(sourceUrl);
|
console.log('Trying to get games from Haifa...');
|
||||||
const parsedResult = (0, node_html_parser_1.parse)(result.data.toString());
|
try {
|
||||||
const gameBoxs = parsedResult.querySelectorAll(".game-box");
|
const result = await axios_1.default.get(sourceUrl);
|
||||||
const games = [];
|
const parsedResult = (0, node_html_parser_1.parse)(result.data.toString());
|
||||||
for (let gameBox of gameBoxs) {
|
const gameBoxs = parsedResult.querySelectorAll(".game-box");
|
||||||
const teamsPlaying = gameBox
|
const games = [];
|
||||||
.querySelectorAll(".team-name")
|
for (let gameBox of gameBoxs) {
|
||||||
.map((team) => team.text);
|
const teamsPlaying = gameBox
|
||||||
const regex = /[\r\n\s]+/g;
|
.querySelectorAll(".team-name")
|
||||||
const gameHeader = gameBox
|
.map((team) => team.text);
|
||||||
.querySelector(".game-header")
|
const regex = /[\r\n\s]+/g;
|
||||||
.text.replace(regex, " ")
|
const gameHeader = gameBox
|
||||||
.trim();
|
.querySelector(".game-header")
|
||||||
const headerSplit = gameHeader.split(",");
|
.text.replace(regex, " ")
|
||||||
// In data, if there is no time, it means it's the last game for the calender
|
.trim();
|
||||||
const lastGameForCalender = headerSplit.length < 4;
|
const headerSplit = gameHeader.split(",");
|
||||||
const location = headerSplit[headerSplit.length - 1].trim();
|
// In data, if there is no time, it means it's the last game for the calender
|
||||||
if (location === 'נדחה')
|
const lastGameForCalender = headerSplit.length < 4;
|
||||||
continue;
|
const location = headerSplit[headerSplit.length - 1].trim();
|
||||||
if (lastGameForCalender)
|
if (location === 'נדחה')
|
||||||
break;
|
continue;
|
||||||
const gameDate = this.findDate(headerSplit);
|
if (lastGameForCalender)
|
||||||
const gameTime = this.findTime(headerSplit);
|
break;
|
||||||
const start = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString();
|
const gameDate = this.findDate(headerSplit);
|
||||||
const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm")
|
const gameTime = this.findTime(headerSplit);
|
||||||
.add(2, "hours")
|
const start = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm").toISOString();
|
||||||
.toISOString();
|
const end = (0, moment_1.default)(gameDate + gameTime, "DD/MM/YYYYHH:mm")
|
||||||
games.push({
|
.add(2, "hours")
|
||||||
summary: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
.toISOString();
|
||||||
location: headerSplit[headerSplit.length - 1].trim(),
|
games.push({
|
||||||
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
summary: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
||||||
start: {
|
location: headerSplit[headerSplit.length - 1].trim(),
|
||||||
dateTime: start,
|
description: `${teamsPlaying[0]} vs. ${teamsPlaying[1]}`,
|
||||||
timeZone: "Asia/Jerusalem",
|
start: {
|
||||||
},
|
dateTime: start,
|
||||||
end: {
|
timeZone: "Asia/Jerusalem",
|
||||||
dateTime: end,
|
},
|
||||||
timeZone: "Asia/Jerusalem",
|
end: {
|
||||||
},
|
dateTime: end,
|
||||||
});
|
timeZone: "Asia/Jerusalem",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// return [];
|
||||||
|
return games;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
// return [];
|
|
||||||
return games;
|
|
||||||
}
|
}
|
||||||
findTime(headerSplit) {
|
findTime(headerSplit) {
|
||||||
let time = '';
|
let time = '';
|
||||||
|
|
|
@ -9,7 +9,7 @@ import moment from "moment"; // require
|
||||||
|
|
||||||
export default class GameSource {
|
export default class GameSource {
|
||||||
async getGamesFromHaifa(): Promise<GoogleCalendarEvent[]> {
|
async getGamesFromHaifa(): Promise<GoogleCalendarEvent[]> {
|
||||||
const sourceUrl = `https://mhaifafc.com/games?lang=en`;
|
const sourceUrl = `http://mhaifafc.com/games?lang=en`;
|
||||||
console.log('Trying to get games from Haifa...');
|
console.log('Trying to get games from Haifa...');
|
||||||
try {
|
try {
|
||||||
const result = await axios.get(sourceUrl);
|
const result = await axios.get(sourceUrl);
|
||||||
|
|
Loading…
Reference in a new issue