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 {
|
||||
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 = '';
|
||||
|
|
|
@ -9,7 +9,7 @@ import moment from "moment"; // require
|
|||
|
||||
export default class GameSource {
|
||||
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...');
|
||||
try {
|
||||
const result = await axios.get(sourceUrl);
|
||||
|
|
Loading…
Reference in a new issue