From 8b87f4975612547b302ef8227e3d8faa3bf4a6ae Mon Sep 17 00:00:00 2001 From: Nigel Nindo Date: Thu, 19 Oct 2023 06:10:29 +0300 Subject: [PATCH] Correctly parse dates --- src/config/orbit.json | 5 ++ src/core/parsers/orbit/parser_types.ts | 66 +++++++++++++++++--------- src/testbed/testbed_1.ts | 4 +- src/testbed/testbed_2.ts | 4 +- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/config/orbit.json b/src/config/orbit.json index 0a86ba5..51581c8 100644 --- a/src/config/orbit.json +++ b/src/config/orbit.json @@ -1,6 +1,11 @@ { "version": "1.0.0", "games": [ + { + "name": "Football", + "betType": "Three Way", + "url": "https://www.orbitxch.com/customer/sport/1" + }, { "name": "Tennis", "betType": "Two Way", diff --git a/src/core/parsers/orbit/parser_types.ts b/src/core/parsers/orbit/parser_types.ts index 3d1a7e5..7c80e96 100644 --- a/src/core/parsers/orbit/parser_types.ts +++ b/src/core/parsers/orbit/parser_types.ts @@ -1,8 +1,10 @@ import * as cheerio from "cheerio"; import _ from "lodash"; +import momentTz from 'moment-timezone'; import { getConfig } from "../../.."; import { Result } from "../../../utils/types/result_type"; +import { TimeZones } from "../../../utils/types/common"; const {logger} = getConfig(); @@ -10,30 +12,40 @@ export function processOrbitThreeWayGamesHtml(html: string): Result { - const data = $(element).find("div.biab_group-markets-table-row"); - - data.each((_, element_1) => { - const teamNames = $(element_1).find("div > div.biab_market-title-team-names"); - const clubA = $(teamNames).find("p:nth-child(1)").text().trim(); - const clubB = $(teamNames).find("p:nth-child(2)").text().trim(); - - const numBets = Number($(element_1).find("div > span.cursor-help").text().trim()); - - const oddsWrapper = $(element_1).find("div.styles_betContent__wrapper__25jEo"); - const odds = $(oddsWrapper).find("div.styles_contents__Kf8LQ > button > span > div > span.styles_betOdds__bxapE"); - const oddsArray: any[] = []; - odds.each((_, element_2) => { - oddsArray.push($(element_2).text().trim()); - }); - - gameEvents.push({ - clubA, - clubB, - numBets, - oddsArray + $("div.biab_group-markets.biab_market-odds-wrapper.styles_collapse__container__2Gov0").each((_, element) => { + const startDate = $(element).find("span.styles_title__lw-Ns").text().trim(); + + $(element).each((_,element_1) => { + const data = $(element_1).find("div.biab_group-markets-table-row"); + + data.each((_, element_2) => { + const teamNames = $(element_2).find("div > div.biab_market-title-team-names"); + const clubA = $(teamNames).find("p:nth-child(1)").text().trim(); + const clubB = $(teamNames).find("p:nth-child(2)").text().trim(); + + const numBets = Number($(element_2).find("div > span.cursor-help").text().trim()); + const startTime = $(element_2).find("div.biab_market-inplay-cell.styles_inPlayCell__laf3g").text().trim().replace(" ", ""); + const parsedTime = startTime.match(timeRegexMatcher); + + const oddsWrapper = $(element_2).find("div.styles_betContent__wrapper__25jEo"); + const odds = $(oddsWrapper).find("div.styles_contents__Kf8LQ > button > span > div > span.styles_betOdds__bxapE"); + const oddsArray: any[] = []; + odds.each((_, element_3) => { + oddsArray.push($(element_3).text().trim()); + }); + + gameEvents.push({ + clubA, + clubB, + numBets, + startDate, + parsedTime, + oddsArray + }); }); }); }); @@ -60,10 +72,20 @@ export function processOrbitThreeWayGamesHtml(html: string): Result { return event.numBets > 9; }); + // remove in-play and game events just about to start + finalMapping = finalMapping.filter(event => { + return event.parsedTime !== null; + }); + + finalMapping = finalMapping.map(item => { + return {...item, ...{eventDate: momentTz(`${item.startDate} ${item.parsedTime[0]}`, "ddd DD MMM HH:mm").toDate()}}; + }); + logger.trace(finalMapping); return {result: "success", value: finalMapping}; diff --git a/src/testbed/testbed_1.ts b/src/testbed/testbed_1.ts index 569d801..ef7260c 100644 --- a/src/testbed/testbed_1.ts +++ b/src/testbed/testbed_1.ts @@ -1,4 +1,4 @@ import { OrbitScrapper } from "../core/scrapping/orbit"; -const betikaScrapper = new OrbitScrapper(); -betikaScrapper.fetchData(); +const scrapper = new OrbitScrapper(); +scrapper.fetchData(); diff --git a/src/testbed/testbed_2.ts b/src/testbed/testbed_2.ts index cc1fb39..8577af2 100644 --- a/src/testbed/testbed_2.ts +++ b/src/testbed/testbed_2.ts @@ -1,4 +1,4 @@ -import { BetikaParser } from "../core/parsers/betika"; +import { OrbitParser } from "../core/parsers/orbit"; -const parser = new BetikaParser() +const parser = new OrbitParser() parser.subscribeToChannels();