Skip to content

Commit

Permalink
Correctly parse dates
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelnindodev committed Oct 19, 2023
1 parent d1eaf37 commit 8b87f49
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/config/orbit.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
66 changes: 44 additions & 22 deletions src/core/parsers/orbit/parser_types.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
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();

export function processOrbitThreeWayGamesHtml(html: string): Result<any[], Error> {
const gameEvents: any[] = [];

const $ = cheerio.load(html);
const timeRegexMatcher = /\d\d:\d\d/g;
momentTz.tz.setDefault(TimeZones.UTC); // highly suspect timezones for orbit are in utc because saw games events from previous day
try {

$("div.rowsContainer").each((_,element) => {
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
});
});
});
});
Expand All @@ -60,10 +72,20 @@ export function processOrbitThreeWayGamesHtml(html: string): Result<any[], Error
return {...event, ...{oddsArray: oddsToNumber}};
});

// filter out games where there is insufficient quorum of player stakes
finalMapping = finalMapping.filter(event => {
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};
Expand Down
4 changes: 2 additions & 2 deletions src/testbed/testbed_1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrbitScrapper } from "../core/scrapping/orbit";

const betikaScrapper = new OrbitScrapper();
betikaScrapper.fetchData();
const scrapper = new OrbitScrapper();
scrapper.fetchData();
4 changes: 2 additions & 2 deletions src/testbed/testbed_2.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 8b87f49

Please sign in to comment.