From 95a848a6c7690e38dfb82f10e8bfb503084dda0a Mon Sep 17 00:00:00 2001 From: Corey Schaf Date: Sat, 30 Mar 2024 10:20:47 -0400 Subject: [PATCH] #47 shift chart endpoint simple addition (#48) * #47 shift chart endpoint simple addition * Bumps version to 2.5.0 --- nhlpy/_version.py | 2 +- nhlpy/api/game_center.py | 17 ++++++++++++++++- pyproject.toml | 2 +- tests/test_game_center.py | 10 ++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/nhlpy/_version.py b/nhlpy/_version.py index 165ba72..581e229 100644 --- a/nhlpy/_version.py +++ b/nhlpy/_version.py @@ -1,3 +1,3 @@ # Should this be driven by the main pyproject.toml file? yes, is it super convoluted? yes, can it wait? sure -__version__ = "2.4.0" +__version__ = "2.5.0" diff --git a/nhlpy/api/game_center.py b/nhlpy/api/game_center.py index 3c03e73..09fd6f0 100644 --- a/nhlpy/api/game_center.py +++ b/nhlpy/api/game_center.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, List from nhlpy.http_client import HttpClient @@ -43,3 +43,18 @@ def score_now(self, date: Optional[str] = None) -> dict: :return: dict """ return self.client.get(resource=f"score/{date if date else 'now'}").json() + + def shift_chart_data(self, game_id: str, excludes: List[str] = None) -> dict: + """ + Get shift chart data for the game_id. GameIds can be retrieved from the schedule endpoint. + :param excludes: List of strings of items to exclude from the response. + :param game_id: The game_id for the game you want the shift chart data for. + :return: dict + """ + if not excludes: + excludes = ["eventDetails"] + + base_url: str = "https://api.nhle.com/stats/rest/en/shiftcharts" + exclude_p: str = ",".join(excludes) + expr_p: str = f"gameId={game_id} and ((duration != '00:00' and typeCode = 517) or typeCode != 517 )" + return self.client.get_by_url(full_resource=f"{base_url}?cayenneExp={expr_p}&exclude={exclude_p}").json() diff --git a/pyproject.toml b/pyproject.toml index 055e9f3..9d7511f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "nhl-api-py" -version = "2.4.0" +version = "2.5.0" description = "NHL API. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods for easy data loading in Pandas or any ML applications." authors = ["Corey Schaf "] readme = "README.md" diff --git a/tests/test_game_center.py b/tests/test_game_center.py index c42f40d..abd53d0 100644 --- a/tests/test_game_center.py +++ b/tests/test_game_center.py @@ -27,3 +27,13 @@ def test_score_now(h_m, nhl_client): nhl_client.game_center.score_now() h_m.assert_called_once() assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/score/now" + + +@mock.patch("httpx.Client.get") +def test_shift_chart_data(h_m, nhl_client): + nhl_client.game_center.shift_chart_data(game_id="2020020001") + h_m.assert_called_once() + assert ( + h_m.call_args[1]["url"] == "https://api.nhle.com/stats/rest/en/shiftcharts?cayenneExp=gameId=2020020001 and " + "((duration != '00:00' and typeCode = 517) or typeCode != 517 )&exclude=eventDetails" + )