Beispiel #1
0
 def __init__(self, event_ids: Union[List[int], int],
              market_ids: Union[List[int], int]):
     super().__init__()
     event_ids = utils.make_list(event_ids)
     market_ids = utils.make_list(market_ids)
     self.name = "bestLines"
     self.arg_str = self._get_args("lines")
     self.args = {"eids": event_ids, "mtids": market_ids}
     self.fields = None
     self._raw = self._build_and_execute_query(self.name,
                                               q_arg_str=self.arg_str,
                                               q_args=self.args)
    def __init__(self, event_ids: Union[List[int], int]):
        super().__init__()
        utils.make_list(event_ids)
        self.name = "eventsV2"
        self.arg_str = self._get_args("event_ids")
        self.args = {"eids": event_ids}
        self.fields = self._get_fields("event")
        self._raw = self._build_and_execute_query(self.name, self.fields,
                                                  self.arg_str, self.args)

        self._subpath_keys = ["events"]
        self._sublist_keys = ["participants", "scores"]
        self._id_key = "event id"
Beispiel #3
0
    def __init__(self, participant_ids: Union[List[int]]):
        # this query only gets the 5 most recent events for a participant.
        super().__init__()
        utils.make_list(participant_ids)
        self.name = "eventsInfoByParticipant"
        self.arg_str = self._get_args("participants")
        self.args = {"partids": participant_ids}
        self.fields = self._get_fields("event")
        self._raw = self._build_and_execute_query(self.name, self.fields,
                                                  self.arg_str, self.args)

        self._subpath_keys = ["events"]
        self._sublist_keys = ["participants", "scores"]
        self._id_key = "event id"
Beispiel #4
0
 def __init__(self, league_ids: Union[List[int], int]):
     super().__init__()
     league_ids = utils.make_list(league_ids)
     self.name = "leagues"
     self.arg_str = self._get_args("league_ids")
     self.args = {"lids": league_ids}
     self.fields = self._get_fields("leagues")
     self._raw = self._build_and_execute_query(self.name, self.fields,
                                               self.arg_str, self.args)
Beispiel #5
0
 def __init__(self, event_id: int, market_ids: Union[List[int], int]):
     super().__init__()
     market_ids = utils.make_list(market_ids)
     self.name = "consensusHistory"
     self.arg_str = self._get_args("consensus_history")
     self.args = {"eid": event_id, "mtids": market_ids}
     self.fields = self._get_fields("consensus_history")
     self._raw = self._build_and_execute_query(
         self.name, self.fields, self.arg_str, self.args
     )
    def __init__(self, system_sportsbook_ids: Union[List[int], int]):
        super().__init__()
        system_sportsbook_ids = utils.make_list(system_sportsbook_ids)
        self.name = "sportsbooks"
        self.arg_str = self._get_args("sportsbooks")
        self.args = {"sbids": system_sportsbook_ids}
        self.fields = self._get_fields("sportsbooks")
        self._raw = self._build_and_execute_query(self.name, self.fields,
                                                  self.arg_str, self.args)

        self._id_key = "sportsbook id"
Beispiel #7
0
    def __init__(self, market_ids: Union[List[int]], sport_id: int):
        super().__init__()
        market_ids = utils.make_list(market_ids)
        self.name = "marketTypesById"
        self.arg_str = self._get_args("market_ids")
        self.args = {"mtids": market_ids, "spids": [sport_id]}
        self.fields = self._get_fields("markets_by_id")
        self._raw = self._build_and_execute_query(self.name, self.fields,
                                                  self.arg_str, self.args)

        self._id_key = "market id"
    def team_ids(self, terms: Union[int, str, List[Union[int,
                                                         str]]]) -> List[int]:
        """Given provided search terms, return a list of matching team ids.

        If search term is string, search for matching team. If search term is
        int, assume that it is the ID, and insert it into the list to be returned.

        This method is provided as a convenience so that you don't need to
        remember team id numbers. Case is ignored for search terms.

        Example search terms:
            Seattle
            Seahawks
            Seattle Seahawks
            sea
            SEA

        Raises:
            TypeError:
                If a search term is not an int or str.
            ValueError:
                If a search term is ambiguous, or cannot be matched with a team.
        """

        terms = utils.make_list(terms)
        ids = []
        for t in terms:
            if isinstance(t, int):
                ids.append(t)
            else:
                old_t = t
                try:
                    t = t.lower()
                except AttributeError:
                    raise TypeError("Search terms must be ints or strings.")
                try:
                    match = [
                        v[t] for k, v in self._team_ids.items() if t in v
                    ][0]
                    ids.append(match)
                except IndexError:
                    raise ValueError(f"Could not find team {old_t}.")
                if isinstance(match, list):
                    raise ValueError(
                        utils.str_format(
                            f"""Search term '{old_t}' is ambiguous.
                            Matching ids: {', '.join([str(m) for m in match])}.
                        """,
                            squish=True,
                        ))
        return list(OrderedDict.fromkeys(ids))
    def __init__(
        self,
        event_id: int,
        market_id: int,
        sportsbook_id: int,
        participant_ids: Union[List[int], int],
    ):
        # only need 1 participant id, it's dumb
        super().__init__()
        utils.make_list(participant_ids)
        self.name = "lineHistory"
        self.arg_str = self._get_args("line_history")
        self.args = {
            "eid": event_id,
            "mtid": market_id,
            "paid": sportsbook_id,
            # partids is required by the lineHistory query
            "partids": participant_ids,
        }
        self.fields = self._get_fields("line_history")

        self._raw = self._build_and_execute_query(
            self.name, self.fields, self.arg_str, self.args
        )
Beispiel #10
0
    def __init__(self, league_ids: Union[List[int], int], dt: datetime):
        super().__init__()
        league_ids = utils.make_list(league_ids)
        self.name = "eventsByDateNew"
        self.arg_str = self._get_args("date")
        self.args = {
            "lids": league_ids,
            "timestamp": utils.datetime_to_timestamp(dt)
        }
        self.fields = self._get_fields("event")
        self._raw = self._build_and_execute_query(self.name, self.fields,
                                                  self.arg_str, self.args)

        self._subpath_keys = ["events"]
        self._sublist_keys = ["participants", "scores"]
        self._id_key = "event id"
    def ids(self, terms: Union[List[Union[int, str]], int, str]) -> List[int]:
        """Take provided search terms and return list of matching sportsbook ids.

        If search term is string, search for matching sportsbook. If search term is
        int, assume that it is the ID, and insert it into the list to be returned.

        This method is provided as a convenience so that you don't need to
        remember sportsbook id numbers. Case is ignored for search terms.

        Example search terms:
            'pinnacle'
            'PINNACLE'
            'bodog'
            'bodog sportsbook'
            20

        Raises:
            TypeError:
                If a provided search term is not an int or str.
            ValueError:
                If a provided search term string cannot be matched with a sportsbook.
        """
        terms = utils.make_list(terms)
        ids = []
        for t in terms:
            if isinstance(t, int):
                ids.append(t)
            else:
                old_t = t
                try:
                    t = t.lower()
                except AttributeError:
                    raise TypeError("Search terms must be ints or strings.")
                try:
                    id = [
                        v[t] for k, v in self._sportsbook_ids.items() if t in v
                    ][0]
                    ids.append(id)
                except IndexError:
                    raise ValueError(f"Could not find sportsbook {old_t}.")

        return list(OrderedDict.fromkeys(ids))
    def market_ids(self, terms: Union[List[Union[int, str]], int,
                                      str]) -> List[int]:
        """Given provided search terms, return a list of matching market ids.

        If search term is string, search for matching betting market. If search term is
        int, assume that it is the ID, and insert it into the list to be returned.

        This method is provided as a convenience so that you don't need to
        remember market id numbers. Case is ignored for search terms.

        A search dictionary is utilized so that you can use common abbrevations /
        spelling variants for markets instead of typing them out / worrying about
        format.

        Example search terms, which all point to the same market id:
            '1st half over/under'
            '1st-half totals'
            '1st half o/u'
            'first half totals'
            'first-half ou'
            '1hou'
            '1htot'
            '1h ou'
            '1h tot'
            '1H OU'
            '1H TOT'
            '1HOU'

        Raises:
            TypeError:
                If a provided search term is not an int or str.
            ValueError:
                If a provided search term string cannot be matched with a market.
        """
        def try_translate(term: str) -> str:
            """Attempt to translate a given search term using the search dictionary.

            If there is no translation for the given string, the original value is
            returned.
            """
            words = term.split(" ")
            translated_words = []
            for w in words:
                try:
                    translated_words.append(search_dict[w])
                except KeyError:
                    translated_words.append(w)
            return " ".join(translated_words)

        def try_match_and_append(term: str, ids: List[int]) -> bool:
            """Attempt to match the search term with a market id.

            If match, append the id to the ids list.
            """
            id = self._market_ids.get(term)
            if id is not None:
                ids.append(id)
                return True
            return False

        def split_word(word: str) -> List[str]:
            """Split a word at index 2 and 3, and join parts with space.

            Split only at index 2 and 3 because the abbreviations in the search
            dictionary are never longer than 3 characters.

            Returned list may be empty for invalid inputs.
            """
            splits = []
            for i in range(2, 4):
                try:
                    splits.append(" ".join([word[:i], word[i:]]))
                except IndexError:
                    pass
            return splits

        def match_term(term: Union[int, str], ids: List[int]) -> bool:
            """Try and match a given search term with a market id."""
            if isinstance(term, int):
                ids.append(term)
                return True
            try:
                term = term.lower().strip()
            except AttributeError:
                raise TypeError("Search terms must be ints or strings.")
            translated_term = try_translate(term)
            if try_match_and_append(translated_term, ids):
                return True
            # The term may be abbreviations concatenated together without a space, for
            # example, '1hou'.
            if len(term.split(" ")) == 1:
                splits = split_word(term)
                for t_split in splits:
                    translated_term = try_translate(t_split)
                    if try_match_and_append(translated_term, ids):
                        return True
            return False

        terms = utils.make_list(terms)
        search_dict = self._search_translations
        ids = []
        for term in terms:
            if not match_term(term, ids):
                raise ValueError(f"Could not find market {term}.")

        return list(OrderedDict.fromkeys(ids))