Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
seasoncountdown now will use the next season info from the NHL api (#417
Browse files Browse the repository at this point in the history
)

Thanks as always !!!!
  • Loading branch information
falkyre committed Jul 31, 2023
1 parent 9e9ed6f commit 5149367
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 12 deletions.
22 changes: 15 additions & 7 deletions src/boards/seasoncountdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rgbmatrix import graphics
from PIL import ImageFont, Image
from utils import center_text
import datetime
from datetime import datetime, date
import debug
from time import sleep
from utils import get_file
Expand All @@ -19,9 +19,17 @@ def __init__(self, data, matrix,sleepEvent):
self.font = data.config.layout.font
self.font.large = data.config.layout.font_large_2
# Current season seems to not update until pre-season start so I will have to modify the Status and the nhl_api to get the coming season.
self.season_start = datetime.date(2021,10,12)
self.days_until_season = (self.season_start - datetime.date.today()).days
#self.season_start = datetime.date(2021,10,12)
self.season_start = datetime.strptime(self.data.status.next_season_start(), '%Y-%m-%d').date()
self.days_until_season = (self.season_start - date.today()).days
self.scroll_pos = self.matrix.width

# Set up season text
current_year = date.today().year
next_year = current_year + 1

self.nextseason="{0}-{1}".format(current_year,next_year)
self.nextseason_short="NHL {0}-{1}".format(str(current_year)[-2:],str(next_year)[-2:])

def draw(self):

Expand All @@ -47,7 +55,7 @@ def season_start_today(self) :

self.matrix.draw_image((15,0), nhl_logo)

debug.info("2021-2022 season has begun")
debug.info("{0} season has begun".format(self.nextseason))

self.matrix.render()
self.sleepEvent.wait(0.5)
Expand All @@ -56,7 +64,7 @@ def season_start_today(self) :
#draw bottom text
self.matrix.draw_text(
(14,25),
"2021-2022",
self.nextseason,
font=self.font,
fill=(0,0,0),
backgroundColor=(155,155,155)
Expand All @@ -74,7 +82,7 @@ def season_countdown(self) :
self.matrix.draw_image((34,0), nhl_logo)
self.matrix.draw_image((-5,0), black_gradiant)

debug.info("Counting down to NHL 21-22")
debug.info("Counting down to {0}".format(self.nextseason_short))

self.matrix.render()
self.sleepEvent.wait(0.5)
Expand Down Expand Up @@ -104,7 +112,7 @@ def season_countdown(self) :
#draw bottom text
self.matrix.draw_text(
(1,25),
"NHL 21-22",
self.nextseason_short,
font=self.font,
fill=(0,0,0),
backgroundColor=(155,155,155)
Expand Down
10 changes: 8 additions & 2 deletions src/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,14 @@ def _is_new_day(self):
# Reset flag
self.all_pref_games_final = False

self.refresh_daily()

#Don't think this is needed to be called a second time
#self.refresh_daily()
self.status.refresh_next_season()

return True
else:
debug.info("It is not a new day")

return False

#
Expand Down Expand Up @@ -579,3 +582,6 @@ def refresh_daily(self):

# Fetch the playoff data
self.refresh_playoff()



33 changes: 30 additions & 3 deletions src/data/status.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime
from nhl_api import game_status_info, current_season_info
from datetime import datetime, date
from nhl_api import game_status_info, current_season_info, next_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 = self.season_info["seasonId"]
self.Preview = []
self.Live = []
Expand All @@ -26,7 +27,17 @@ def __init__(self):
self.GameOver.append(status['detailedState'])
else:
self.Final.append(status['detailedState'])


# # 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)

self.refresh_next_season()


def is_scheduled(self, status):
return status in self.Preview
Expand Down Expand Up @@ -62,5 +73,21 @@ def is_playoff(self, date, playoff_obj):
except TypeError:
debug.error('The Argument provided for status.is_playoff is missing or not right.')
return False

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)


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


2 changes: 2 additions & 0 deletions src/nhl_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def game_status_info():
def current_season_info():
return nhl_api.info.current_season()

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

def standings():
try:
Expand Down
16 changes: 16 additions & 0 deletions src/nhl_api/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import requests
import debug
from datetime import date

"""
TODO:
Expand All @@ -15,6 +16,7 @@
OVERVIEW_URL = BASE_URL + 'game/{0}/feed/live?site=en_nhl'
STATUS_URL = BASE_URL + 'gameStatus'
CURRENT_SEASON_URL = BASE_URL + 'seasons/current'
NEXT_SEASON_URL = BASE_URL + 'seasons/{0}'
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 Expand Up @@ -69,6 +71,20 @@ def get_current_season():
return data
except requests.exceptions.RequestException as e:
raise ValueError(e)

def get_next_season():
# Create the next seasonID from the current year and curent year +1 eg: 20232024 is seasonID for 2023-2024 season
# This will return an empty set for seasons data if the seasonID has nothing, a 200 response will always occur
current_year = date.today().year
next_year = current_year + 1

nextseasonID="{0}{1}".format(current_year,next_year)

try:
data = requests.get(NEXT_SEASON_URL.format(nextseasonID), timeout=REQUEST_TIMEOUT)
return data
except requests.exceptions.RequestException as e:
raise ValueError(e)


def get_standings():
Expand Down
4 changes: 4 additions & 0 deletions src/nhl_api/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def current_season():
data = nhl_api.data.get_current_season().json()
return data

def next_season():
data = nhl_api.data.get_next_season().json()
return data


def playoff_info(season):
data = nhl_api.data.get_playoff_data(season)
Expand Down

0 comments on commit 5149367

Please sign in to comment.