jayteealao / NaijaBet_Api

A python library that provides access to the odds data of Nigeria's major betting sites
MIT License
9 stars 5 forks source link

Updates needed to API. #1

Closed KingdeJosh closed 1 year ago

KingdeJosh commented 1 year ago

Issue1: The Nairabet link is invalid or no more works.
That the error you get 2023-05-18 18:14:14,374 - bookmakers.BaseClass - ERROR - HTTP error occurred: 404 Client Error: Not Found for url: https://www.nairabet.com/rest/market/categories/multi/135763/events 2023-05-18 18:14:14,374 - bookmakers.BaseClass - ERROR - Response content: b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message></Error>" It needs to be updated.

Issue 2: The .json normalizer files need some updates with the new style of teams on each site. I added a logger to get the teams that are missing. Olympique Marseille not found in betking_normalizer.json normalizer Stade Brest 29 not found in betking_normalizer.json normalizer RC Lens not found in betking_normalizer.json normalizer AC Ajaccio not found in betking_normalizer.json normalizer Stade Rennes not found in betking_normalizer.json normalizer

If you can add the other betting sites. that will be nice.

Some of my updated version of your code if it helps normalizer.py

`import json
import re
from typing import ChainMap
import arrow
from pathlib import Path
import difflib
from utils.logger import get_logger

logger = get_logger(__name__)

def match_normalizer(list, pathstr: str):
    path = Path(__file__).parent / pathstr
    if list is None:
        return {}
    data = list[:]

    def helper(string):
        with open(path, "r") as f:
            normalizer = json.load(f)
            try:
                return normalizer[string]
            except KeyError:
                logger.warning(f"{string} not found in {pathstr} normalizer")
                path_b9 = Path(__file__).parent / "bet9ja_normalizer.json"
                path_bk = Path(__file__).parent / "betking_normalizer.json"
                path_nb = Path(__file__).parent / "nairabet_normalizer.json"

                map = ChainMap(
                    json.load(open(path_b9, "r")),
                    json.load(open(path_bk, "r")),
                    json.load(open(path_nb, "r")))
                try:
                    return map[string]
                except KeyError:
                    logger.warning(f"{string} not found in normalizer")
                    res = difflib.get_close_matches(string, map.keys(), 1, 0.8)
                    if res:
                        logger.warning(f'found possible matches {res}')
                        return map[res[0]]
                    else:
                        logger.warning(f"No close match found for {string}")
                        return string  # Return the original string if no match is found

    for event in data:
        teams = event["match"]
        home, away = re.split(r"\s-\s", teams, maxsplit=1)
        home = helper(home.strip())
        away = helper(away.strip())
        event["match"] = "{0} - {1}".format(home, away)
        event["time"] = arrow.get(event["time"]).int_timestamp
        event['league'] = helper(event['league'])

    return data

def bet9ja_match_normalizer(list):
    return match_normalizer(list, "bet9ja_normalizer.json")

def nairabet_match_normalizer(list):
    return match_normalizer(list, "nairabet_normalizer.json")

def betking_match_normalizer(list):
    return match_normalizer(list, "betking_normalizer.json")

`
jayteealao commented 1 year ago

Thanks for bringing this to my atention, havent used the api in a while, ill update it over the next few days which betting sites would you like to see added

KingdeJosh commented 1 year ago

As much as possible. Possibly the top 10 in Nigeria.