Skip to content

Commit

Permalink
Update season data and fix 0 day padding
Browse files Browse the repository at this point in the history
  • Loading branch information
ELepolt committed Dec 2, 2023
1 parent d76fdc2 commit 21cfe1b
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 24 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ephem==3.7.7.0
fastjsonschema>=2.14.4
geocoder==1.38.1
gpiozero==1.5.1
nhl-api-client==1.0.4
nhl-api-client==1.0.5
noaa-sdk>=0.1.18
printtools==1.2
PyInstaller==3.6
Expand Down
2 changes: 1 addition & 1 deletion src/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def refresh_games(self):
attempts_remaining = 5
while attempts_remaining > 0:
try:
data = nhl_api.data.get_score_details("{}-{}-{}".format(self.year, self.month, self.day))
data = nhl_api.data.get_score_details(self.date().strftime("%Y-%m-%d"))
if not data:
self.games = []
self.pref_games = []
Expand Down
33 changes: 17 additions & 16 deletions src/data/status.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from datetime import datetime, date
from nhl_api import game_status_info, current_season_info, next_season_info
from nhl_api import game_status_info, current_season_info
import debug

class Status:
def __init__(self):
game_status = [] # game_status_info()
# self.season_info = current_season_info()['seasons'][0]
#self.next_season_info = next_season_info()['seasons'][0]
self.season_id = 20232024 # self.season_info["seasonId"]
self.refresh_next_season()
self.season_id = self.season_info.id
self.Preview = []
self.Live = []
self.GameOver = []
self.Final = []
self.Irregular = []

# TODO: I don't know that we have this type of status anymore.
for status in game_status:
if status['code'] == '8' or status['code'] == '9':
self.Irregular.append(status['detailedState'])
Expand Down Expand Up @@ -56,8 +56,8 @@ def is_irregular(self, status):

def is_offseason(self, date):
try:
regular_season_startdate = datetime.strptime(self.season_info['regularSeasonStartDate'], "%Y-%m-%d").date()
end_of_season = datetime.strptime(self.season_info['seasonEndDate'], "%Y-%m-%d").date()
regular_season_startdate = datetime.strptime(self.season_info['startDate'], '%Y-%m-%dT%H:%M:%S').date()
end_of_season = datetime.strptime(self.season_info['endDate'], '%Y-%m-%dT%H:%M:%S').date()
return date < regular_season_startdate or date > end_of_season
except:
debug.error('The Argument provided for status.is_offseason is missing or not right.')
Expand All @@ -76,18 +76,19 @@ def is_playoff(self, date, playoff_obj):

def refresh_next_season(self):
debug.info("Updating next season info")
self.season_info = current_season_info()['seasons'][0]
self.next_season_info = next_season_info()['seasons'][0]
# Make sure that the next_season_info is not an empty list, if it is, make next_season = to current season

if not self.next_season_info:
debug.info("Next season info unavailable, defaulting to Oct 1 of current year as start of new season")
self.next_season_info = self.season_info
# Arbitrarily set the regularSeasonStartDate to Oct 1 of current year
self.next_season_info['regularSeasonStartDate'] = "{0}-10-01".format(date.today().year)
all_seasons = current_season_info()
self.season_info = all_seasons.data[-2]
self.next_season_info = all_seasons.data[-1]
next_season_start = self.next_season_info.preseason_startdate
next_season_end = self.next_season_info.end_date
now = datetime.now()
# My theory is that the 'next season' will show up at some point before the current season ends.
# So operate as if the current season is second from last, and check to see if the 'next season' is really current
if next_season_start < now and now < next_season_end:
self.season_info = self.next_season_info


def next_season_start(self):
return self.next_season_info['regularSeasonStartDate']
return self.next_season_info.preseason_startdate


12 changes: 8 additions & 4 deletions src/nhl_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import nhl_api.info
from nhl_api_client import Client
from nhl_api_client.api.game import get_game_play_by_play_by_id
from nhl_api_client.api.default import get_season_standings_by_date
from nhl_api_client.api.default import get_season_standings_by_date, get_all_season_details
from nhl_api_client.models import SeasonStandings
import datetime

Expand All @@ -27,10 +27,14 @@ def game_status_info():


def current_season_info():
return nhl_api.info.current_season()
client = Client(base_url="https://api.nhle.com")
season_details = {}
with client as client:
season_details = get_all_season_details.sync(client=client)
return season_details

def next_season_info():
return nhl_api.info.next_season()
# def next_season_info():
# return nhl_api.info.next_season()

def standings():
# TODO: Wildcard stuff
Expand Down
4 changes: 2 additions & 2 deletions src/nhl_api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
PLAYER_URL = '{0}people/{1}'
OVERVIEW_URL = BASE_URL + 'gamecenter/{0}/play-by-play'
STATUS_URL = BASE_URL + 'gameStatus'
CURRENT_SEASON_URL = BASE_URL + 'seasons/current'
NEXT_SEASON_URL = BASE_URL + 'seasons/{0}'
CURRENT_SEASON_URL = 'https://api.nhle.com/stats/rest/en/season'
NEXT_SEASON_URL = 'https://api.nhle.com/stats/rest/en/season'
STANDINGS_URL = BASE_URL + 'standings'
STANDINGS_WILD_CARD = STANDINGS_URL + '/wildCardWithLeaders'
PLAYOFF_URL = BASE_URL + "tournaments/playoffs?expand=round.series,schedule.game.seriesSummary&season={}"
Expand Down
160 changes: 160 additions & 0 deletions swagger/nhl.json
Original file line number Diff line number Diff line change
Expand Up @@ -4621,6 +4621,166 @@
},
"security": []
}
},
"/stats/rest/en/season": {
"get": {
"summary": "/stats/rest/en/season",
"description": "**Host**: http://api.nhle.com",
"operationId": "GetAllSeasonDetails",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"allStarGameInUse": {
"type": "integer"
},
"conferencesInUse": {
"type": "integer"
},
"divisionsInUse": {
"type": "integer"
},
"endDate": {
"type": "string",
"format": "date-time"
},
"entryDraftInUse": {
"type": "integer"
},
"formattedSeasonId": {
"type": "string"
},
"minimumPlayoffMinutesForGoalieStatsLeaders": {
"type": "integer"
},
"minimumRegularGamesForGoalieStatsLeaders": {
"type": "integer"
},
"nhlStanleyCupOwner": {
"type": "integer"
},
"numberOfGames": {
"type": "integer"
},
"olympicsParticipation": {
"type": "integer"
},
"pointForOTLossInUse": {
"type": "integer"
},
"preseasonStartdate": {
"type": "string",
"format": "date-time",
"nullable": true
},
"regularSeasonEndDate": {
"type": "string",
"format": "date-time"
},
"rowInUse": {
"type": "integer"
},
"seasonOrdinal": {
"type": "integer"
},
"startDate": {
"type": "string",
"format": "date-time"
},
"supplementalDraftInUse": {
"type": "integer"
},
"tiesInUse": {
"type": "integer"
},
"totalPlayoffGames": {
"type": "integer"
},
"totalRegularSeasonGames": {
"type": "integer"
},
"wildcardInUse": {
"type": "integer"
}
},
"required": [
"id",
"allStarGameInUse",
"conferencesInUse",
"divisionsInUse",
"endDate",
"entryDraftInUse",
"formattedSeasonId",
"minimumPlayoffMinutesForGoalieStatsLeaders",
"minimumRegularGamesForGoalieStatsLeaders",
"nhlStanleyCupOwner",
"numberOfGames",
"olympicsParticipation",
"pointForOTLossInUse",
"preseasonStartdate",
"regularSeasonEndDate",
"rowInUse",
"seasonOrdinal",
"startDate",
"supplementalDraftInUse",
"tiesInUse",
"totalPlayoffGames",
"totalRegularSeasonGames",
"wildcardInUse"
]
}
},
"total": {
"type": "integer"
}
},
"required": [
"data",
"total"
]
}
}
},
"description": "",
"headers": {
"cf-cache-status": {
"required": false,
"schema": {
"type": "string"
}
},
"cf-ray": {
"required": false,
"schema": {
"type": "string"
}
}
}
}
},
"security": [],
"parameters": [
{
"name": "sort",
"in": "query",
"required": false,
"schema": {
"type": "string"
}
}
]
}
}
},
"components": {
Expand Down

0 comments on commit 21cfe1b

Please sign in to comment.