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

1st #100

Closed
wants to merge 1 commit into from
Closed

1st #100

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
655 changes: 655 additions & 0 deletions nhlpy/data/ANA_player_stats.json

Large diffs are not rendered by default.

640 changes: 640 additions & 0 deletions nhlpy/data/ANA_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/BOS_player_stats.json

Large diffs are not rendered by default.

627 changes: 627 additions & 0 deletions nhlpy/data/BOS_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/BUF_player_stats.json

Large diffs are not rendered by default.

636 changes: 636 additions & 0 deletions nhlpy/data/BUF_roster.json

Large diffs are not rendered by default.

551 changes: 551 additions & 0 deletions nhlpy/data/CAR_player_stats.json

Large diffs are not rendered by default.

606 changes: 606 additions & 0 deletions nhlpy/data/CAR_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/CBJ_player_stats.json

Large diffs are not rendered by default.

710 changes: 710 additions & 0 deletions nhlpy/data/CBJ_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/CGY_player_stats.json

Large diffs are not rendered by default.

669 changes: 669 additions & 0 deletions nhlpy/data/CGY_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/CHI_player_stats.json

Large diffs are not rendered by default.

620 changes: 620 additions & 0 deletions nhlpy/data/CHI_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/COL_player_stats.json

Large diffs are not rendered by default.

581 changes: 581 additions & 0 deletions nhlpy/data/COL_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/DAL_player_stats.json

Large diffs are not rendered by default.

622 changes: 622 additions & 0 deletions nhlpy/data/DAL_roster.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions nhlpy/data/DET_player_stats.json

Large diffs are not rendered by default.

606 changes: 606 additions & 0 deletions nhlpy/data/DET_roster.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions nhlpy/data/EDM_player_stats.json

Large diffs are not rendered by default.

617 changes: 617 additions & 0 deletions nhlpy/data/EDM_roster.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions nhlpy/data/FLA_player_stats.json

Large diffs are not rendered by default.

552 changes: 552 additions & 0 deletions nhlpy/data/FLA_roster.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions nhlpy/data/LAK_player_stats.json

Large diffs are not rendered by default.

595 changes: 595 additions & 0 deletions nhlpy/data/LAK_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/MIN_player_stats.json

Large diffs are not rendered by default.

659 changes: 659 additions & 0 deletions nhlpy/data/MIN_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/MTL_player_stats.json

Large diffs are not rendered by default.

552 changes: 552 additions & 0 deletions nhlpy/data/MTL_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/NJD_player_stats.json

Large diffs are not rendered by default.

580 changes: 580 additions & 0 deletions nhlpy/data/NJD_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/NSH_player_stats.json

Large diffs are not rendered by default.

625 changes: 625 additions & 0 deletions nhlpy/data/NSH_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/NYI_player_stats.json

Large diffs are not rendered by default.

675 changes: 675 additions & 0 deletions nhlpy/data/NYI_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/NYR_player_stats.json

Large diffs are not rendered by default.

586 changes: 586 additions & 0 deletions nhlpy/data/NYR_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/OTT_player_stats.json

Large diffs are not rendered by default.

676 changes: 676 additions & 0 deletions nhlpy/data/OTT_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/PHI_player_stats.json

Large diffs are not rendered by default.

631 changes: 631 additions & 0 deletions nhlpy/data/PHI_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/PIT_player_stats.json

Large diffs are not rendered by default.

582 changes: 582 additions & 0 deletions nhlpy/data/PIT_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/SEA_player_stats.json

Large diffs are not rendered by default.

625 changes: 625 additions & 0 deletions nhlpy/data/SEA_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/SJS_player_stats.json

Large diffs are not rendered by default.

643 changes: 643 additions & 0 deletions nhlpy/data/SJS_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/STL_player_stats.json

Large diffs are not rendered by default.

617 changes: 617 additions & 0 deletions nhlpy/data/STL_roster.json

Large diffs are not rendered by default.

629 changes: 629 additions & 0 deletions nhlpy/data/TBL_player_stats.json

Large diffs are not rendered by default.

540 changes: 540 additions & 0 deletions nhlpy/data/TBL_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/TOR_player_stats.json

Large diffs are not rendered by default.

693 changes: 693 additions & 0 deletions nhlpy/data/TOR_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/UTA_player_stats.json

Large diffs are not rendered by default.

640 changes: 640 additions & 0 deletions nhlpy/data/UTA_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/VAN_player_stats.json

Large diffs are not rendered by default.

606 changes: 606 additions & 0 deletions nhlpy/data/VAN_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/VGK_player_stats.json

Large diffs are not rendered by default.

591 changes: 591 additions & 0 deletions nhlpy/data/VGK_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/WPG_player_stats.json

Large diffs are not rendered by default.

616 changes: 616 additions & 0 deletions nhlpy/data/WPG_roster.json

Large diffs are not rendered by default.

655 changes: 655 additions & 0 deletions nhlpy/data/WSH_player_stats.json

Large diffs are not rendered by default.

701 changes: 701 additions & 0 deletions nhlpy/data/WSH_roster.json

Large diffs are not rendered by default.

482 changes: 482 additions & 0 deletions nhlpy/data/teams.json

Large diffs are not rendered by default.

1,124 changes: 628 additions & 496 deletions poetry.lock

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest
import json
import os
from nhlpy import NHLClient
from nhlpy.api.query.builder import QueryBuilder
from nhlpy.api.query.filters.season import SeasonQuery
from nhlpy.api.query.filters.franchise import FranchiseQuery
import time


@pytest.fixture
def nhl_client():
"""Fixture to create an NHL client instance."""
return NHLClient(verbose=True)


def save_json(data, filename):
"""
Save data as a JSON file in the `nhlpy/data` directory.
"""
output_dir = os.path.join("nhlpy", "data")
os.makedirs(output_dir, exist_ok=True) # Create directory if it doesn't exist
filepath = os.path.join(output_dir, filename)
with open(filepath, "w") as f:
json.dump(data, f, indent=4)
print(f"Saved data to {filepath}")


def test_get_all_teams(nhl_client):
"""
Test fetching all NHL teams and save to JSON.
"""
teams = nhl_client.teams.teams_info()
assert isinstance(teams, list), "Teams should be a list"
assert len(teams) > 0, "Teams list should not be empty"
save_json(teams, "teams.json") # Save teams data as JSON


def test_get_roster_players(nhl_client):
"""
Test fetching roster players for each team and save to JSON.
"""
teams = nhl_client.teams.teams_info()
for team in teams:
players = nhl_client.teams.roster(team_abbr=team["abbr"], season="20242025")
filename = f"{team['abbr']}_roster.json"
save_json(players, filename) # Save each team's roster as JSON


def test_get_player_summary_stats(nhl_client):
"""
Test fetching summary statistics for players and save to JSON.
"""
teams = nhl_client.teams.teams_info()
query_builder = QueryBuilder()
season_query = SeasonQuery(season_start="20242025", season_end="20242025")

for team in teams:
time.sleep(1) # Pause to avoid rate limiting
franchise_query = FranchiseQuery(franchise_id=team["franchise_id"])
context = query_builder.build(filters=[franchise_query, season_query])

data = nhl_client.stats.skater_stats_with_query_context(
report_type="summary",
query_context=context,
aggregate=True,
)
if "data" in data:
filename = f"{team['abbr']}_player_stats.json"
save_json(data, filename) # Save player stats for each team as JSON