Skip to content

Commit

Permalink
Get demo dates working
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-porter committed Mar 15, 2024
1 parent e0a1e0b commit af3646a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
21 changes: 21 additions & 0 deletions rewrite/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from datetime import datetime, timedelta

from config.layout import Layout
from config.colors import Colors

Expand All @@ -9,6 +11,7 @@

class Config:
REFERENCE_FILENAME = "config.json.example"
DATE_FORMAT = "%Y-%m-%d"

def __init__(self, config_filename, width, height):
self.width = width
Expand All @@ -23,6 +26,14 @@ def __init__(self, config_filename, width, height):
self.layout = Layout(width, height)
self.colors = Colors()

self.__set_end_of_day()

def today(self):
if self.demo_date:
return datetime.strptime(self.demo_date, Config.DATE_FORMAT)

return datetime.today() - timedelta(hours=self.eod_hours, minutes=self.eod_minutes)

def __fetch_config(self, name):
"""
Loads a config (JSON-formatted) with a custom filename. Falls back to a default if not found.
Expand Down Expand Up @@ -79,3 +90,13 @@ def __set_log_level(self):
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.WARNING)

def __set_end_of_day(self):
try:
hours, minutes = [int(part) for part in self.end_of_day.split(":")]
except:
hours, minutes = 0, 0
ScoreboardLogger.warning(f"Expected 24 hour time for end_of_day in format '12:34'. Received {self.end_of_day}. Defaulting to '00:00'.")

self.eod_hours = hours
self.eod_minutes = minutes
4 changes: 4 additions & 0 deletions rewrite/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ def __init__(self, screen_manager):

def request_next_screen(self, screen, **kwargs):
self.screen_manager.request_next_screen(screen, **kwargs)

@property
def config(self):
return self.screen_manager.config
9 changes: 3 additions & 6 deletions rewrite/data/schedule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import statsapi, time

from datetime import datetime as dt

from utils import logger as ScoreboardLogger

from data.update_status import UpdateStatus
Expand All @@ -28,10 +26,10 @@ def __init__(self, data):
def update(self):
self.last_update = time.time()

ScoreboardLogger.log(f"Updating schedule for {dt.today()}")
ScoreboardLogger.log(f"Updating schedule for {self.data.config.today()}")

try:
self.__fetch_updated_schedule(dt.today())
self.__fetch_updated_schedule(self.data.config.today())
except Exception as exception:
ScoreboardLogger.exception("Networking error while refreshing schedule!")
ScoreboardLogger.exception(exception)
Expand All @@ -50,8 +48,7 @@ def request_next_game(self):
self.__request_transition_to_game(self.game)

def __fetch_updated_schedule(self, date):
# self._games = statsapi.schedule(date.strftime("%Y-%m-%d"))
self._games = statsapi.schedule(date.strftime("2024-03-12"))
self._games = statsapi.schedule(date.strftime("%Y-%m-%d"))

self.games = [Game.from_schedule(game) for game in self._games]

Expand Down

0 comments on commit af3646a

Please sign in to comment.