Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/get orbit game events estimated start time utc #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/core/scrapping/orbit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class OrbitScrapper extends BaseScrapper {

if (getHtmlResult.result === "success") {
logger.info("Successfully fetched html for url. ", metadata);
logger.info(getHtmlResult.value.html);
this.publishRawHtmlToRedis(
getRedisPublisherResult.value,
getRedisHtmlParserChannelName(this.betProvider, game),
Expand Down
57 changes: 34 additions & 23 deletions src/testbed/build_scrapers/orbit/three_way/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,54 @@ const {logger} = getConfig();

class OrbitThreeWayTestBed {
public async run() {
const htmlDataResult = await readFileAsync("data/test_html/orbit/football.html");
const timeRegexMatcher = /\d\d:\d\d/g;
const htmlDataResult = await readFileAsync("data/test_html/orbit/tennis.html");
if (htmlDataResult.result === "success") {
logger.info("Success fetching html");
const $ = cheerio.load(htmlDataResult.value);

$("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();

/**
* Bypassing .biab_group-markets-table div and going directly to .rowContainer
*/
$("div.rowsContainer").each((_,element) => {
const data = $(element).find("div.biab_group-markets-table-row");
/**
* Bypassing .biab_group-markets-table div and going directly to .rowContainer
*/
$(element).each((_,element_1) => {
const data = $(element_1).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();
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 = $(element_1).find("div > span.cursor-help").text().trim();
const numBets = $(element_2).find("div > span.cursor-help").text().trim();

const oddsWrapper = $(element_1).find("div.styles_betContent__wrapper__25jEo");
const startTime = $(element_2).find("div.biab_market-inplay-cell.styles_inPlayCell__laf3g").text().trim().replace(" ", "");

//const oddFinder = "div.styles_contents__Kf8LQ > button > span > div > span.styles_betOdds__bxapE";
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 oddFinder = "div.styles_contents__Kf8LQ > button > span > div > span.styles_betOdds__bxapE";

// expecting 3 pairs of odds for W,D,L. So 6 in total
const oddsArray = [];
odds.each((_, element_2) => {
oddsArray.push($(element_2).text().trim());
logger.trace($(element_2).text().trim());
});
const odds = $(oddsWrapper).find("div.styles_contents__Kf8LQ > button > span > div > span.styles_betOdds__bxapE");

// expecting 3 pairs of odds for W,D,L. So 6 in total
const oddsArray = [];
odds.each((_, element_3) => {
oddsArray.push($(element_3).text().trim());
logger.trace($(element_3).text().trim());
});

const parsedTime = startTime.match(timeRegexMatcher);

logger.trace(`${clubA} vs ${clubB}`);
logger.trace("numBets: ", numBets);
//logger.trace("odd1: ", $(oddsWrapper).find(`${oddFinder}:nth-child(1)`));
logger.trace(`${clubA} vs ${clubB}`);
logger.trace("numBets: ", numBets);
logger.trace("startDate: ", startDate);
logger.trace("startTime: ", parsedTime);
//logger.trace("odd1: ", $(oddsWrapper).find(`${oddFinder}:nth-child(1)`));
});
});


});
} else {
const message = "Could not get html data";
Expand Down
4 changes: 0 additions & 4 deletions src/testbed/testbed.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/testbed/testbed_1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { OrbitScrapper } from "../core/scrapping/orbit";

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();