Skip to content

Commit

Permalink
Get three way odd types for Betika working as well (much easier than …
Browse files Browse the repository at this point in the history
…anticipated)
  • Loading branch information
nigelnindodev committed Oct 7, 2023
1 parent 3e7ccfb commit 85ca613
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/config/betika.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"name": "Tennis Singles",
"betType": "Two Way",
"url": "https://www.betika.com/lite/en-ke/?tab_id=-2&sub_type_id=1,186&sport_id=28"
},
{
"name": "Basketball",
"betType": "Three Way",
"url": "https://www.betika.com/lite/en-ke/?sport_id=30&tag_id=&tab_id=-2"
}
]
}
30 changes: 24 additions & 6 deletions src/core/parsers/betika/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { BetProvider } from "../../../bet_providers";
import { BetikaProvider } from "../../../bet_providers/betika";
import { RedisSingleton } from "../../../datastores/redis";
import { getRedisHtmlParserChannelName } from "../../../utils/redis";
import { RawHtmlForProcessingMessage } from "../../../utils/types/common";
import { BetTypes, RawHtmlForProcessingMessage } from "../../../utils/types/common";
import { Result } from "../../../utils/types/result_type";
import { processBetikaTwoWayGamesHtml } from "./parser_types";
import { processBetikaThreeWayGamesHtml, processBetikaTwoWayGamesHtml } from "./parser_types";

const {logger} = getConfig();

Expand Down Expand Up @@ -58,16 +58,34 @@ export class BetikaParser extends BaseParser {
}

private processRawHtmlMessage(parsedMessage: RawHtmlForProcessingMessage): void {
const results = processBetikaTwoWayGamesHtml(parsedMessage.rawHtml);
if (results.result === "success") {
logger.info("Successfully fetched games: ", results.value);
let results2;
switch (parsedMessage.betType) {
case BetTypes.TWO_WAY:
results2 = processBetikaTwoWayGamesHtml(parsedMessage.rawHtml);
break;
case BetTypes.THREE_WAY:
results2 = processBetikaThreeWayGamesHtml(parsedMessage.rawHtml);
break;
default:
const message = "Unknown bet type provided";
logger.error(message, {
betProviderName: parsedMessage.betProviderName,
betType: parsedMessage.betType,
fromUrl: parsedMessage.fromUrl,
gameName: parsedMessage.gameName
});
throw new Error(`Unknown bet type provided for provider: ${this.betProvider.name}`);
}

if (results2.result == "success") {
logger.info("Successfully fetched games: ", results2.value);
} else {
logger.error("Failed to parse html into games: ", {
betProviderName: parsedMessage.betProviderName,
betType: parsedMessage.betType,
fromUrl: parsedMessage.fromUrl,
gameName: parsedMessage.gameName,
errorMessage: results.value.message
errorMessage: results2.value.message
});
}
}
Expand Down
29 changes: 28 additions & 1 deletion src/core/parsers/betika/parser_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,31 @@ export function processBetikaTwoWayGamesHtml(html: string): Result<any[], Error>
logger.error('An error occurred while parsing Betika two way html data: ', e.message);
return {result: "error", value: new Error(e.message)};
}
}
}

export function processBetikaThreeWayGamesHtml(html: string): Result<any[], Error> {
const gameEvents: any[] = [];
const $ = cheerio.load(html);
try {
$("div:not(.odds-title).game.highlights--item").each((_, element) => {
momentTz.tz.setDefault(TimeZones.NAIROBI);
const clubsAndOdds = $(element).find("div.teams-info-vert.big-screen");
gameEvents.push({
clubA: $(clubsAndOdds).find("div.teams-info-vert-left > a > div:nth-child(1)").text().trim(),
clubB: $(clubsAndOdds).find("div.teams-info-vert-left > a > div:nth-child(2)").text().trim(),
estimatedStartTimeUtc: momentTz(
$(element).find("div.teams-info-meta.big-screen > div.teams-info-meta-right").text().trim(),
"DD/MM HH:mm").toDate(),
league: $(element).find("div.teams-info-meta.big-screen > div.teams-info-meta-left").text().trim(),
oddsAWin: Number($(clubsAndOdds).find("button.match-odd.odd1 > div.odds__value").text().trim()),
oddsDraw: Number($(clubsAndOdds).find("button.match-odd.odd2 > div.odds__value").text().trim()),
oddsBWin: Number($(clubsAndOdds).find("button.match-odd.odd3 > div.odds__value").text().trim()),
link: $(clubsAndOdds).find("div.teams-info-vert-left > a").attr("href"),
});
});
return {result: "success", value: gameEvents};
} catch (e: any) {
logger.error('An error occurred while parsing Betika two way html data: ', e.message);
return {result: "error", value: new Error(e.message)};
}
}
3 changes: 2 additions & 1 deletion src/utils/types/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export enum BetProviders {
}

export enum Games {
BASKETBALL = "BasketBall",
FOOTBALL = "Football",
TENNIS_SINGLES = "Tennis Singles",
TENNIS_SINGLES = "Tennis Singles", // TODO: Add string trimming here
TENNIS_DOUBLES = "Tennis Doubles"
}

Expand Down

0 comments on commit 85ca613

Please sign in to comment.