From 90ded076c2bebeb6ddef2cda3419c3d9a0b96269 Mon Sep 17 00:00:00 2001 From: todd Date: Sun, 20 Oct 2024 09:05:09 -0400 Subject: [PATCH 1/4] fix(nflgt): shield api inaccessible chore(nflgt): code formatting ver(nflgt): 2.4.2 ver(mynflapi): 2.5.1 ver(platform): 2024.10.5 --- bots/nfl_game_threads/__init__.py | 390 +++++++++++++-------- bots/nfl_game_threads/mynflapi/__init__.py | 3 + bots/nfl_game_threads/mynflapi/version.py | 2 +- redball/version.py | 2 +- 4 files changed, 242 insertions(+), 155 deletions(-) diff --git a/bots/nfl_game_threads/__init__.py b/bots/nfl_game_threads/__init__.py index b390d7c..e6c3a52 100644 --- a/bots/nfl_game_threads/__init__.py +++ b/bots/nfl_game_threads/__init__.py @@ -32,7 +32,7 @@ import praw -__version__ = "2.4.1" +__version__ = "2.4.2" DATA_LOCK = threading.Lock() @@ -99,9 +99,11 @@ def run(self): self.log.debug(f"Could not shut down scheduler because: {e}") self.bot.SCHEDULER = BackgroundScheduler( - timezone=tzlocal.get_localzone() - if str(tzlocal.get_localzone()) != "local" - else "America/New_York" + timezone=( + tzlocal.get_localzone() + if str(tzlocal.get_localzone()) != "local" + else "America/New_York" + ) ) self.bot.SCHEDULER.start() @@ -334,11 +336,12 @@ def run(self): isCanceled = False if myTeamTodayGameId: + gameInsights = None # TODO: Need data source # Get game insights now so we can check for cancelation headlines - gameInsights = self.nfl.gameInsights(gameId=myTeamTodayGameId)["data"][ - "viewer" - ]["gameInsight"]["insightsByGames"] - isCanceled = self.isGameCanceled(gameInsights) + # gameInsights = self.nfl.gameInsights(gameId=myTeamTodayGameId)["data"][ + # "viewer" + # ]["gameInsight"]["insightsByGames"] + # isCanceled = self.isGameCanceled(gameInsights) if not myTeamTodayGameId or (myTeamTodayGameId and isCanceled): # It's not a game day @@ -362,9 +365,12 @@ def run(self): homeAway = ( "home" if todayGames[myGameIndex]["homeTeam"]["id"] == self.myTeam["id"] - else "away" - if todayGames[myGameIndex]["awayTeam"]["id"] == self.myTeam["id"] - else None + else ( + "away" + if todayGames[myGameIndex]["awayTeam"]["id"] + == self.myTeam["id"] + else None + ) ) self.log.debug(f"My team is [{homeAway}] (homeAway)") oppTeam = todayGames[myGameIndex][ @@ -872,9 +878,11 @@ def tailgate_thread_update_loop(self): { "text": tailgateThreadText, "thread": tailgateThread, - "title": tailgateThread.title - if tailgateThread not in [None, False] - else None, + "title": ( + tailgateThread.title + if tailgateThread not in [None, False] + else None + ), } ) # Only sticky when posting the thread @@ -901,9 +909,11 @@ def tailgate_thread_update_loop(self): { "text": tailgateThreadText, "thread": tailgateThread, - "title": tailgateThread.title - if tailgateThread not in [None, False] - else None, + "title": ( + tailgateThread.title + if tailgateThread not in [None, False] + else None + ), } ) skipFlag = True @@ -1132,9 +1142,11 @@ def game_thread_update_loop(self): { "thread": gameThread, "text": gameThreadText, - "title": gameThread.title - if gameThread not in [None, False] - else None, + "title": ( + gameThread.title + if gameThread not in [None, False] + else None + ), } ) # Only sticky when posting the thread @@ -1295,9 +1307,11 @@ def game_thread_update_loop(self): { "thread": gameThread, "text": gameThreadText, - "title": gameThread.title - if gameThread not in [None, False] - else None, + "title": ( + gameThread.title + if gameThread not in [None, False] + else None + ), } ) @@ -1335,16 +1349,15 @@ def game_thread_update_loop(self): if text != self.threadCache["game"].get("text") and text != "": self.threadCache["game"].update({"text": text}) # Add last updated timestamp - text += ( - """ + text += """ -^^^Last ^^^Updated: ^^^""" - + self.convert_timezone( - datetime.utcnow(), - self.settings.get("Bot", {}).get( - "TEAM_TIMEZONE", "America/New_York" - ), - ).strftime("%m/%d/%Y ^^^%I:%M:%S ^^^%p ^^^%Z") +^^^Last ^^^Updated: ^^^""" + self.convert_timezone( + datetime.utcnow(), + self.settings.get("Bot", {}).get( + "TEAM_TIMEZONE", "America/New_York" + ), + ).strftime( + "%m/%d/%Y ^^^%I:%M:%S ^^^%p ^^^%Z" ) self.threadCache["game"]["thread"].edit(text) self.log.info("Edits submitted for game thread.") @@ -1634,9 +1647,11 @@ def postgame_thread_update_loop(self): { "thread": postGameThread, "text": postGameThreadText, - "title": postGameThread.title - if postGameThread not in [None, False] - else None, + "title": ( + postGameThread.title + if postGameThread not in [None, False] + else None + ), } ) # Only sticky when posting the thread @@ -1660,9 +1675,11 @@ def postgame_thread_update_loop(self): { "thread": postGameThread, "text": postGameThreadText, - "title": postGameThread.title - if postGameThread not in [None, False] - else None, + "title": ( + postGameThread.title + if postGameThread not in [None, False] + else None + ), } ) if not postGameThread: @@ -1692,16 +1709,15 @@ def postgame_thread_update_loop(self): self.log.debug(f"Rendered post game thread text: {text}") if text != self.threadCache["post"]["text"] and text != "": self.threadCache["post"]["text"] = text - text += ( - """ + text += """ -^^^Last ^^^Updated: ^^^""" - + self.convert_timezone( - datetime.utcnow(), - self.settings.get("Bot", {}).get( - "TEAM_TIMEZONE", "America/New_York" - ), - ).strftime("%m/%d/%Y ^^^%I:%M:%S ^^^%p ^^^%Z") +^^^Last ^^^Updated: ^^^""" + self.convert_timezone( + datetime.utcnow(), + self.settings.get("Bot", {}).get( + "TEAM_TIMEZONE", "America/New_York" + ), + ).strftime( + "%m/%d/%Y ^^^%I:%M:%S ^^^%p ^^^%Z" ) self.threadCache["post"]["thread"].edit(text) self.log.info("Post game thread edits submitted.") @@ -1936,9 +1952,10 @@ def collect_data(self): "otherTodayGamesDetails": otherTodayGamesDetails, } ) - gameInsights = self.nfl.gameInsights(gameId=self.allData["gameId"])["data"][ - "viewer" - ]["gameInsight"]["insightsByGames"] + # gameInsights = self.nfl.gameInsights(gameId=self.allData["gameId"])["data"][ + # "viewer" + # ]["gameInsight"]["insightsByGames"] + gameInsights = None gameTime = next( ( self.convert_timezone( # Convert Zulu to my team TZ @@ -2156,40 +2173,60 @@ def prep_and_post(self, thread, postFooter=None): flair = ( self.settings.get("Tailgate Thread", {}).get("FLAIR", "") if thread == "tailgate" - else self.settings.get("Game Thread", {}).get("FLAIR", "") - if thread == "game" - else self.settings.get("Post Game Thread", {}).get("FLAIR", "") - if thread == "post" - else "" + else ( + self.settings.get("Game Thread", {}).get("FLAIR", "") + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get("FLAIR", "") + if thread == "post" + else "" + ) + ) ) sort = ( self.settings.get("Tailgate Thread", {}).get("SUGGESTED_SORT", "new") if thread == "tailgate" - else self.settings.get("Game Thread", {}).get("SUGGESTED_SORT", "new") - if thread == "game" - else self.settings.get("Post Game Thread", {}).get("SUGGESTED_SORT", "new") - if thread == "post" - else "new" + else ( + self.settings.get("Game Thread", {}).get("SUGGESTED_SORT", "new") + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get( + "SUGGESTED_SORT", "new" + ) + if thread == "post" + else "new" + ) + ) ) liveDiscussion = ( self.settings.get("Tailgate Thread", {}).get("LIVE_DISCUSSION", False) if thread == "tailgate" - else self.settings.get("Game Thread", {}).get("LIVE_DISCUSSION", False) - if thread == "game" - else self.settings.get("Post Game Thread", {}).get("LIVE_DISCUSSION", False) - if thread == "post" - else False + else ( + self.settings.get("Game Thread", {}).get("LIVE_DISCUSSION", False) + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get( + "LIVE_DISCUSSION", False + ) + if thread == "post" + else False + ) + ) ) lockPrevious = ( False if thread == "tailgate" - else self.settings.get("Game Thread", {}).get("LOCK_TAILGATE_THREAD", False) - if thread == "game" - else self.settings.get("Post Game Thread", {}).get( - "LOCK_GAME_THREAD", False + else ( + self.settings.get("Game Thread", {}).get("LOCK_TAILGATE_THREAD", False) + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get( + "LOCK_GAME_THREAD", False + ) + if thread == "post" + else False + ) ) - if thread == "post" - else False ) restrictSelfPosts = ( False @@ -2285,15 +2322,19 @@ def prep_and_post(self, thread, postFooter=None): "WEBHOOK{}_URL".format(s) ) if thread == "tailgate" - else self.settings.get("Game Thread", {}).get( - "WEBHOOK{}_URL".format(s) - ) - if thread == "game" - else self.settings.get("Post Game Thread", {}).get( - "WEBHOOK{}_URL".format(s) + else ( + self.settings.get("Game Thread", {}).get( + "WEBHOOK{}_URL".format(s) + ) + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get( + "WEBHOOK{}_URL".format(s) + ) + if thread == "post" + else None + ) ) - if thread == "post" - else None ) if webhook_url: self.log.debug( @@ -2316,9 +2357,11 @@ def prep_and_post(self, thread, postFooter=None): self.log.info( "Webhook [{}] result: {}.".format( webhook_url, - webhook_result - if isinstance(webhook_result, str) - else "success", + ( + webhook_result + if isinstance(webhook_result, str) + else "success" + ), ) ) else: @@ -2383,18 +2426,22 @@ def prep_and_post(self, thread, postFooter=None): if threadToLock := ( self.threadCache["tailgate"].get("thread") if thread == "game" - else self.threadCache["game"].get("thread") - if thread == "post" - else None + else ( + self.threadCache["game"].get("thread") + if thread == "post" + else None + ) ): commentText = ( self.settings.get("Game Thread", {}).get("LOCK_MESSAGE", None) if thread == "game" - else self.settings.get("Post Game Thread", {}).get( - "LOCK_MESSAGE", None + else ( + self.settings.get("Post Game Thread", {}).get( + "LOCK_MESSAGE", None + ) + if thread == "post" + else None ) - if thread == "post" - else None ) if not commentText: commentText = f"This thread has been locked. Please continue the discussion in the [{'game' if thread == 'game' else 'post game' if thread == 'post' else 'new'} thread](link)." @@ -2616,11 +2663,15 @@ def render_template(self, thread, templateType, **kwargs): templateFilename = ( self.settings.get("Tailgate Thread", {}).get(setting, "") if thread == "tailgate" - else self.settings.get("Game Thread", {}).get(setting, "") - if thread == "game" - else self.settings.get("Post Game Thread", {}).get(setting, "") - if thread == "post" - else "" + else ( + self.settings.get("Game Thread", {}).get(setting, "") + if thread == "game" + else ( + self.settings.get("Post Game Thread", {}).get(setting, "") + if thread == "post" + else "" + ) + ) ) self.log.debug(f"templateFilename: {templateFilename}") try: @@ -2947,78 +2998,107 @@ def bot_state(self): "enabled": self.settings.get("Tailgate Thread", {}).get( "ENABLED", True ), - "postTime": self.threadCache.get("tailgate", {}) - .get("postTime_local") - .strftime("%m/%d/%Y %I:%M:%S %p") - if isinstance( - self.threadCache.get("tailgate", {}).get("postTime_local"), - datetime, - ) - else "", - "posted": True - if self.threadCache.get("tailgate", {}).get("thread") - else False, - "id": self.threadCache.get("tailgate", {}).get("thread").id - if self.threadCache.get("tailgate", {}).get("thread") - else None, - "url": self.threadCache.get("tailgate", {}).get("thread").shortlink - if self.threadCache.get("tailgate", {}).get("thread") - else None, - "title": self.threadCache.get("tailgate", {}).get("title") - if self.threadCache.get("tailgate", {}).get("thread") - else None, + "postTime": ( + self.threadCache.get("tailgate", {}) + .get("postTime_local") + .strftime("%m/%d/%Y %I:%M:%S %p") + if isinstance( + self.threadCache.get("tailgate", {}).get("postTime_local"), + datetime, + ) + else "" + ), + "posted": ( + True + if self.threadCache.get("tailgate", {}).get("thread") + else False + ), + "id": ( + self.threadCache.get("tailgate", {}).get("thread").id + if self.threadCache.get("tailgate", {}).get("thread") + else None + ), + "url": ( + self.threadCache.get("tailgate", {}).get("thread").shortlink + if self.threadCache.get("tailgate", {}).get("thread") + else None + ), + "title": ( + self.threadCache.get("tailgate", {}).get("title") + if self.threadCache.get("tailgate", {}).get("thread") + else None + ), }, "game": { "gameId": self.allData.get("gameId"), "status": self.allData.get("gameDetails", {}).get("phase"), "oppTeam": deepcopy(self.allData.get("oppTeam")), "homeAway": self.allData.get("homeAway"), - "gameTime": self.allData["gameTime"]["myTeam"].strftime( - "%I:%M %p %Z" - ) - if self.allData.get("gameTime", {}).get("myTeam") - else "Unknown game time", + "gameTime": ( + self.allData["gameTime"]["myTeam"].strftime("%I:%M %p %Z") + if self.allData.get("gameTime", {}).get("myTeam") + else "Unknown game time" + ), "threads": { "game": { "enabled": self.settings.get("Game Thread", {}).get( "ENABLED", True ), - "postTime": self.threadCache["game"] - .get("postTime_local") - .strftime("%m/%d/%Y %I:%M:%S %p") - if isinstance( - self.threadCache["game"].get("postTime_local"), datetime - ) - else "", - "posted": True - if self.threadCache["game"].get("thread") - else False, - "id": self.threadCache["game"].get("thread").id - if self.threadCache["game"].get("thread") - else None, - "url": self.threadCache["game"].get("thread").shortlink - if self.threadCache["game"].get("thread") - else None, - "title": self.threadCache["game"].get("title") - if self.threadCache["game"].get("thread") - else None, + "postTime": ( + self.threadCache["game"] + .get("postTime_local") + .strftime("%m/%d/%Y %I:%M:%S %p") + if isinstance( + self.threadCache["game"].get("postTime_local"), + datetime, + ) + else "" + ), + "posted": ( + True + if self.threadCache["game"].get("thread") + else False + ), + "id": ( + self.threadCache["game"].get("thread").id + if self.threadCache["game"].get("thread") + else None + ), + "url": ( + self.threadCache["game"].get("thread").shortlink + if self.threadCache["game"].get("thread") + else None + ), + "title": ( + self.threadCache["game"].get("title") + if self.threadCache["game"].get("thread") + else None + ), }, "post": { "enabled": self.settings.get("Post Game Thread", {}).get( "ENABLED", True ), - "posted": True - if self.threadCache["post"].get("thread") - else False, - "id": self.threadCache["post"].get("thread").id - if self.threadCache["post"].get("thread") - else None, - "url": self.threadCache["post"].get("thread").shortlink - if self.threadCache["post"].get("thread") - else None, - "title": self.threadCache["post"].get("title") - if self.threadCache["post"].get("thread") - else None, + "posted": ( + True + if self.threadCache["post"].get("thread") + else False + ), + "id": ( + self.threadCache["post"].get("thread").id + if self.threadCache["post"].get("thread") + else None + ), + "url": ( + self.threadCache["post"].get("thread").shortlink + if self.threadCache["post"].get("thread") + else None + ), + "title": ( + self.threadCache["post"].get("title") + if self.threadCache["post"].get("thread") + else None + ), }, }, }, @@ -3197,8 +3277,12 @@ def getNflToken(self, nflSession=None): "Content-Type": "application/json", } body = { - "clientKey": self.settings.get("NFL", {}).get("NFL_API_CLIENT_KEY", "4cFUW6DmwJpzT9L7LrG3qRAcABG5s04g"), - "clientSecret": self.settings.get("NFL", {}).get("NFL_API_CLIENT_SECRET", "CZuvCL49d9OwfGsR"), + "clientKey": self.settings.get("NFL", {}).get( + "NFL_API_CLIENT_KEY", "4cFUW6DmwJpzT9L7LrG3qRAcABG5s04g" + ), + "clientSecret": self.settings.get("NFL", {}).get( + "NFL_API_CLIENT_SECRET", "CZuvCL49d9OwfGsR" + ), "deviceId": "", "deviceInfo": "", "networkType": "other", @@ -3220,7 +3304,7 @@ def getNflToken(self, nflSession=None): def checkNflToken(self, nfl): try: - nfl.currentWeek() + nfl.weekByDate(self.today["Y-m-d"]) except requests.exceptions.HTTPError as e: if "401" in str(e): self.log.warning( diff --git a/bots/nfl_game_threads/mynflapi/__init__.py b/bots/nfl_game_threads/mynflapi/__init__.py index 6973be4..65762a6 100644 --- a/bots/nfl_game_threads/mynflapi/__init__.py +++ b/bots/nfl_game_threads/mynflapi/__init__.py @@ -265,6 +265,9 @@ def teamById_shield(self, teamId, query=None): ) def team_roster(self, propertyId, query=None): + return {"data": {"viewer": {"clubs": {"currentClubRoster": {}}}}} + + def team_roster_shield(self, propertyId, query=None): if not query: query = QUERIES["shield"]["teamRoster"].format(param_propertyId=propertyId) return self.api_call( diff --git a/bots/nfl_game_threads/mynflapi/version.py b/bots/nfl_game_threads/mynflapi/version.py index 2fdf169..935c3a4 100644 --- a/bots/nfl_game_threads/mynflapi/version.py +++ b/bots/nfl_game_threads/mynflapi/version.py @@ -1 +1 @@ -VERSION = "2.5" +VERSION = "2.5.1" diff --git a/redball/version.py b/redball/version.py index 2180869..484d35d 100644 --- a/redball/version.py +++ b/redball/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "2024.10.4" +VERSION = "2024.10.5" From f4d52e5fa5ba0c5e9adabe5ab004440c1680fef9 Mon Sep 17 00:00:00 2001 From: todd Date: Sat, 26 Oct 2024 20:08:03 -0400 Subject: [PATCH 2/4] fix(nhlgt): data moved around between api endpoints ver(nhlgt): 2.1 ver(nhlapi): 0.2 ver(platform): 2024.10.6 --- bots/nhl_game_threads/__init__.py | 6 +- bots/nhl_game_threads/pynhlapi/__init__.py | 2 +- bots/nhl_game_threads/pynhlapi/api.py | 7 +++ bots/nhl_game_threads/pynhlapi/constants.py | 1 + .../templates/game_stats.mako | 54 ++++++++++------ .../nhl_game_threads/templates/linescore.mako | 6 +- .../templates/post_thread.mako | 62 +++++++++---------- .../nhl_game_threads/templates/scratches.mako | 4 ++ bots/nhl_game_threads/templates/skaters.mako | 12 ++-- redball/version.py | 2 +- 10 files changed, 94 insertions(+), 62 deletions(-) diff --git a/bots/nhl_game_threads/__init__.py b/bots/nhl_game_threads/__init__.py index 4101041..a1c6ced 100644 --- a/bots/nhl_game_threads/__init__.py +++ b/bots/nhl_game_threads/__init__.py @@ -32,7 +32,7 @@ import praw -__version__ = "2.0.14" +__version__ = "2.1" DATA_LOCK = threading.Lock() @@ -283,6 +283,7 @@ def run(self): self.log.info("IT'S GAME DAY!") self.log.debug(f"Gathering initial data for gamePk [{gamePk}]...") game = self.nhl.game(gamePk) + game_right_rail = self.nhl.game_right_rail(gamePk) homeAway = ( "home" if game["homeTeam"]["id"] == self.myTeam["id"] @@ -347,6 +348,7 @@ def run(self): "myTeam": gameTime, }, "game": game, + "game_right_rail": game_right_rail, "game_boxscore": game_boxscore, "game_pbp": game_pbp, "standings": standings, @@ -1685,6 +1687,7 @@ def collect_data(self): ] self.log.debug(f"Gathering data for gamePk [{self.allData['gamePk']}]...") game = self.nhl.game(self.allData["gamePk"]) + game_right_rail = self.nhl.game_right_rail(self.allData["gamePk"]) homeAway = ( "home" if game["homeTeam"]["id"] == self.myTeam["id"] @@ -1749,6 +1752,7 @@ def collect_data(self): "myTeam": gameTime, }, "game": game, + "game_right_rail": game_right_rail, "game_boxscore": game_boxscore, "game_pbp": game_pbp, "todayOtherGames": todayOtherGames, diff --git a/bots/nhl_game_threads/pynhlapi/__init__.py b/bots/nhl_game_threads/pynhlapi/__init__.py index 77fd4b4..788082d 100644 --- a/bots/nhl_game_threads/pynhlapi/__init__.py +++ b/bots/nhl_game_threads/pynhlapi/__init__.py @@ -3,6 +3,6 @@ from .constants import APP_NAME from .api import API -__version__ = "0.1.1" +__version__ = "0.2" logger = logging.Logger(APP_NAME) diff --git a/bots/nhl_game_threads/pynhlapi/api.py b/bots/nhl_game_threads/pynhlapi/api.py index 9ba65e9..3dfe689 100644 --- a/bots/nhl_game_threads/pynhlapi/api.py +++ b/bots/nhl_game_threads/pynhlapi/api.py @@ -18,6 +18,13 @@ def game(self, game_pk, **kwargs): if json: return json + def game_right_rail(self, game_pk, **kwargs): + url = f"{constants.RIGHT_RAIL_ENDPOINT.format(game_pk=game_pk)}" + url = self.add_kwargs_to_url(url, kwargs) + json = self.get_json(url) + if json: + return json + def game_boxscore(self, game_pk, **kwargs): url = f"{constants.GAME_BOXSCORE_ENDPOINT.format(game_pk=game_pk)}" url = self.add_kwargs_to_url(url, kwargs) diff --git a/bots/nhl_game_threads/pynhlapi/constants.py b/bots/nhl_game_threads/pynhlapi/constants.py index e6cf4ff..7cc52ba 100644 --- a/bots/nhl_game_threads/pynhlapi/constants.py +++ b/bots/nhl_game_threads/pynhlapi/constants.py @@ -5,6 +5,7 @@ SCOREBOARD_ENDPOINT = API_URL + "/v1/score/{ymd}" SCHEDULE_ENDPOINT = API_URL + "/v1/schedule/{ymd}" GAME_ENDPOINT = API_URL + "/v1/gamecenter/{game_pk}/landing" +RIGHT_RAIL_ENDPOINT = API_URL + "/v1/gamecenter/{game_pk}/right-rail" SEASONS_ENDPOINT = "https://api.nhle.com/stats/rest/en/season?sort=%5B%7B%22property%22:%22id%22,%22direction%22:%22DESC%22%7D%5D" GAME_BOXSCORE_ENDPOINT = API_URL + "/v1/gamecenter/{game_pk}/boxscore" GAME_PLAYBYPLAY_ENDPOINT = API_URL + "/v1/gamecenter/{game_pk}/play-by-play" diff --git a/bots/nhl_game_threads/templates/game_stats.mako b/bots/nhl_game_threads/templates/game_stats.mako index aceb2b2..74b0a90 100644 --- a/bots/nhl_game_threads/templates/game_stats.mako +++ b/bots/nhl_game_threads/templates/game_stats.mako @@ -7,38 +7,54 @@ data["myTeam"] if data["homeAway"] == "home" else data["oppTeam"] ) - awayStats = data["game_boxscore"].get("awayTeam") - homeStats = data["game_boxscore"].get("homeTeam") + #awayStats = data["game_boxscore"].get("awayTeam") + #homeStats = data["game_boxscore"].get("homeTeam") + stats = { + x.get("category", "foo"): (x.get("awayValue", "-"), x.get("homeValue", "-")) for x in data["game_right_rail"].get("teamGameStats", []) + } + placeholder = ("-", "-") %>\ ${'##'} Game Stats -||SOG|FO%|PP|PIM|Hits|Blks| -|:--|:--|:--|:--|:--|:--|:--| +||SOG|FO%|PP|PIM|Hits|Blks|GA|TA| +|:--|:--|:--|:--|:--|:--|:--|:--|:--| ## Team -|[${awayTeam["commonName"]["default"]}](${data["teamSubs"][awayTeam["abbrev"]]})|${awayStats.get("sog", "-")}|${str(round(float(awayStats["faceoffWinningPctg"]))) + "%" if awayStats.get("faceoffWinningPctg") else "-"}|\ -${awayStats.get("powerPlayConversion", "-")}|\ -${awayStats.get("pim", "-")}|${awayStats.get("hits", "-")}|${awayStats.get("blocks", "-")}| -|[${homeTeam["commonName"]["default"]}](${data["teamSubs"][homeTeam["abbrev"]]})|${homeStats.get("sog", "-")}|${str(round(float(homeStats.get("faceoffWinningPctg", 0)))) + "%" if awayStats.get("faceoffWinningPctg") else "-"}|\ -${homeStats.get("powerPlayConversion", "-")}|\ -${homeStats.get("pim", "-")}|${homeStats.get("hits", "-")}|${homeStats.get("blocks", "-")}| +|[${awayTeam["commonName"]["default"]}](${data["teamSubs"][awayTeam["abbrev"]]})|\ +${stats.get("sog", placeholder)[0]}|\ +${(str(round(stats.get("faceoffWinningPctg", placeholder)[0] * 100)) + "%") if stats.get("faceoffWinningPctg") else "-"}|\ +${stats.get("powerPlay", placeholder)[0]}|\ +${stats.get("pim", placeholder)[0]}|\ +${stats.get("hits", placeholder)[0]}|\ +${stats.get("blockedShots", placeholder)[0]}|\ +${stats.get("giveaways", placeholder)[0]}|\ +${stats.get("takeaways", placeholder)[0]}| +|[${homeTeam["commonName"]["default"]}](${data["teamSubs"][homeTeam["abbrev"]]})|\ +${stats.get("sog", placeholder)[1]}|\ +${(str(round(stats.get("faceoffWinningPctg", placeholder)[1] * 100)) + "%") if stats.get("faceoffWinningPctg") else "-"}|\ +${stats.get("powerPlay", placeholder)[1]}|\ +${stats.get("pim", placeholder)[1]}|\ +${stats.get("hits", placeholder)[1]}|\ +${stats.get("blockedShots", placeholder)[1]}|\ +${stats.get("giveaways", placeholder)[1]}|\ +${stats.get("takeaways", placeholder)[1]}| <% - awayF = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("forwards", []) + awayF = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("forwards", []) awayL = [x for x in awayF if x["position"] == "L"] awayC = [x for x in awayF if x["position"] == "C"] awayR = [x for x in awayF if x["position"] == "R"] - awayD = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("defense", []) - awayG = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("goalies", []) + awayD = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("defense", []) + awayG = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("goalies", []) awaySkaters = awayF + awayD awayOnIce_dict = data["game_pbp"].get("awayTeam", {}).get("onIce", []) awayOnIce = [x.get("playerId") for x in awayOnIce_dict] awaySkatersOnIce = [x for x in awaySkaters if x["playerId"] in awayOnIce] awaySkatersOnBench = [x for x in awaySkaters if x["playerId"] not in awayOnIce] - homeF = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("forwards", []) + homeF = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("forwards", []) homeL = [x for x in homeF if x["position"] == "L"] homeC = [x for x in homeF if x["position"] == "C"] homeR = [x for x in homeF if x["position"] == "R"] - homeD = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("defense", []) - homeG = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("goalies", []) + homeD = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("defense", []) + homeG = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("goalies", []) homeSkaters = homeF + homeD homeOnIce_dict = data["game_pbp"].get("homeTeam", {}).get("onIce", []) homeOnIce = [x.get("playerId") for x in homeOnIce_dict] @@ -52,17 +68,17 @@ ${homeStats.get("pim", "-")}|${homeStats.get("hits", "-")}|${homeStats.get("bloc \ % for info in [(awayTeam, awaySkatersOnIce, awaySkatersOnBench, awayG, awayOnIce), (homeTeam, homeSkatersOnIce, homeSkatersOnBench, homeG, homeOnIce)]: % if len(info[1]) or len(info[2]): -|[${info[0]["commonName"]["default"]}](${data["teamSubs"][info[0]["abbrev"]]}) Skaters|G|A|+/-|S|Blk|PIM|FO|TOI| +|[${info[0]["commonName"]["default"]}](${data["teamSubs"][info[0]["abbrev"]]}) Skaters|G|A|+/-|S|Blk|PIM|FO%|TOI| |:--|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:| % for p in info[1] + info[2]: |^${p['position']} ${'**' if p in info[1] else ''}${playerLink(p)}${'**' if p in info[1] else ''}|\ ${p.get("goals", "-")}|\ ${p.get("assists", "-")}|\ ${p.get("plusMinus", "-")}|\ -${p.get("shots", "-")}|\ +${p.get("sog", "-")}|\ ${p.get("blockedShots", "-")}|\ ${p.get("pim", "-")}|\ -${p.get("faceoffs", "-")}|\ +${(str(round(p.get("faceoffWinningPctg", 0.0) * 100)) + "%") if p.get("faceoffWinningPctg") else "-"}|\ ${p.get("toi", "-")}| % endfor % endif diff --git a/bots/nhl_game_threads/templates/linescore.mako b/bots/nhl_game_threads/templates/linescore.mako index c215949..16df656 100644 --- a/bots/nhl_game_threads/templates/linescore.mako +++ b/bots/nhl_game_threads/templates/linescore.mako @@ -7,7 +7,7 @@ data["myTeam"] if data["homeAway"] == "home" else data["oppTeam"] ) - linescore = data["game"].get("summary", {}).get("linescore", {}).get("byPeriod", []) + linescore = data["game_right_rail"].get("linescore", {}).get("byPeriod", []) ordDict = {1:{1:'1st',2:'2nd',3:'3rd',4:'OT',5:'SO'},2:{1:'1st',2:'2nd',3:'3rd',4:'OT',5:'SO'},3:{1:'1st',2:'2nd',3:'3rd',4:'OT1',5:'OT2',6:'OT3',7:'OT4',8:'OT5'}} periodOrd = ordDict[data["game"]["gameType"]] if linescore: @@ -22,8 +22,8 @@ homeLine += f'{period["home"]}|' headerLine += "|TOTAL|" alignmentLine += ":--|:--|" - awayLine += f'|{data["game"].get("summary", {}).get("linescore", {}).get("totals", {}).get("away")}|' - homeLine += f'|{data["game"].get("summary", {}).get("linescore", {}).get("totals", {}).get("home")}|' + awayLine += f'|{data["game_right_rail"].get("linescore", {}).get("totals", {}).get("away")}|' + homeLine += f'|{data["game_right_rail"].get("linescore", {}).get("totals", {}).get("home")}|' %>\ % if linescore: ${'##'} Linescore diff --git a/bots/nhl_game_threads/templates/post_thread.mako b/bots/nhl_game_threads/templates/post_thread.mako index 241197b..8d59eba 100644 --- a/bots/nhl_game_threads/templates/post_thread.mako +++ b/bots/nhl_game_threads/templates/post_thread.mako @@ -55,52 +55,52 @@ ${data["oppTeam"]["commonName"]["default"]} % endif %endif -% if data["game_boxscore"].get("gameVideo", {}).get("threeMinRecap") or data["game_boxscore"].get("gameVideo", {}).get("condensedGame") or data["game_boxscore"].get("boxscore", {}).get("gameReports"): +% if data["game_right_rail"].get("gameVideo", {}).get("threeMinRecap") or data["game_right_rail"].get("gameVideo", {}).get("condensedGame") or data["game_right_rail"].get("gameReports"): ${'##'} Game Videos/Summaries -% if data["game_boxscore"].get("gameVideo", {}).get("threeMinRecap"): -* [Three Minute Recap Video](${highlight_url(data["game_boxscore"]["gameVideo"]["threeMinRecap"])}) +% if data["game_right_rail"].get("gameVideo", {}).get("threeMinRecap"): +* [Three Minute Recap Video](${highlight_url(data["game_right_rail"]["gameVideo"]["threeMinRecap"])}) % endif -% if data["game_boxscore"].get("gameVideo", {}).get("condensedGame"): -* [Condensed Game Video](${highlight_url(data["game_boxscore"]["gameVideo"]["condensedGame"])}) +% if data["game_right_rail"].get("gameVideo", {}).get("condensedGame"): +* [Condensed Game Video](${highlight_url(data["game_right_rail"]["gameVideo"]["condensedGame"])}) % endif -% if data["game_boxscore"].get("boxscore", {}).get("gameReports"): -% if data["game_boxscore"]["boxscore"]["gameReports"].get("gameSummary"): -* [Game Summary](${data["game_boxscore"]["boxscore"]["gameReports"]["gameSummary"]}) +% if data["game_right_rail"].get("gameReports"): +% if data["game_right_rail"]["gameReports"].get("gameSummary"): +* [Game Summary](${data["game_right_rail"]["gameReports"]["gameSummary"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("eventSummary"): -* [Event Summary](${data["game_boxscore"]["boxscore"]["gameReports"]["eventSummary"]}) +% if data["game_right_rail"]["gameReports"].get("eventSummary"): +* [Event Summary](${data["game_right_rail"]["gameReports"]["eventSummary"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("playByPlay"): -* [Play by Play](${data["game_boxscore"]["boxscore"]["gameReports"]["playByPlay"]}) +% if data["game_right_rail"]["gameReports"].get("playByPlay"): +* [Play by Play](${data["game_right_rail"]["gameReports"]["playByPlay"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("faceoffSummary") or data["game_boxscore"]["boxscore"]["gameReports"].get("faceoffComparison"): +% if data["game_right_rail"]["gameReports"].get("faceoffSummary") or data["game_right_rail"]["gameReports"].get("faceoffComparison"): * Face Off \ -% if data["game_boxscore"]["boxscore"]["gameReports"].get("faceoffSummary"): -[Summary](${data["game_boxscore"]["boxscore"]["gameReports"]["faceoffSummary"]}) \ +% if data["game_right_rail"]["gameReports"].get("faceoffSummary"): +[Summary](${data["game_right_rail"]["gameReports"]["faceoffSummary"]}) \ % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("faceoffComparison"): -[Comparison](${data["game_boxscore"]["boxscore"]["gameReports"]["faceoffComparison"]}) +% if data["game_right_rail"]["gameReports"].get("faceoffComparison"): +[Comparison](${data["game_right_rail"]["gameReports"]["faceoffComparison"]}) % endif % endif -##% if data["game_boxscore"]["boxscore"]["gameReports"].get("rosters"): -##* [Rosters](${data["game_boxscore"]["boxscore"]["gameReports"]["rosters"]}) -##% endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("shotSummary"): -* [Shot Summary](${data["game_boxscore"]["boxscore"]["gameReports"]["shotSummary"]}) +% if data["game_right_rail"]["gameReports"].get("rosters"): +* [Rosters](${data["game_right_rail"]["gameReports"]["rosters"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("shootoutSummary"): -* [Shootout Summary](${data["game_boxscore"]["boxscore"]["gameReports"]["shootoutSummary"]}) +% if data["game_right_rail"]["gameReports"].get("shotSummary"): +* [Shot Summary](${data["game_right_rail"]["gameReports"]["shotSummary"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("shiftChart"): -* [Shift Chart](${data["game_boxscore"]["boxscore"]["gameReports"]["shiftChart"]}) +% if data["game_right_rail"]["gameReports"].get("shootoutSummary"): +* [Shootout Summary](${data["game_right_rail"]["gameReports"]["shootoutSummary"]}) % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("toiAway") or data["game_boxscore"]["boxscore"]["gameReports"].get("toiHome"): +% if data["game_right_rail"]["gameReports"].get("shiftChart"): +* [Shift Chart](${data["game_right_rail"]["gameReports"]["shiftChart"]}) +% endif +% if data["game_right_rail"]["gameReports"].get("toiAway") or data["game_right_rail"]["gameReports"].get("toiHome"): * TOI Report: \ -% if data["game_boxscore"]["boxscore"]["gameReports"].get("toiAway"): -[${awayTeam["commonName"]["default"]}](${data["game_boxscore"]["boxscore"]["gameReports"]["toiAway"]}) \ +% if data["game_right_rail"]["gameReports"].get("toiAway"): +[${awayTeam["commonName"]["default"]}](${data["game_right_rail"]["gameReports"]["toiAway"]}) \ % endif -% if data["game_boxscore"]["boxscore"]["gameReports"].get("toiHome"): -[${homeTeam["commonName"]["default"]}](${data["game_boxscore"]["boxscore"]["gameReports"]["toiHome"]}) +% if data["game_right_rail"]["gameReports"].get("toiHome"): +[${homeTeam["commonName"]["default"]}](${data["game_right_rail"]["gameReports"]["toiHome"]}) % endif % endif % endif diff --git a/bots/nhl_game_threads/templates/scratches.mako b/bots/nhl_game_threads/templates/scratches.mako index d606cf4..53ffbab 100644 --- a/bots/nhl_game_threads/templates/scratches.mako +++ b/bots/nhl_game_threads/templates/scratches.mako @@ -3,11 +3,15 @@ awayScratches = data["game"].get("matchup", {}).get("gameInfo", {}).get("awayTeam", {}).get("scratches", None) if not awayScratches: awayScratches = data["game"].get("summary", {}).get("gameInfo", {}).get("awayTeam", {}).get("scratches", None) + if not awayScratches: + awayScratches = data["game_right_rail"].get("gameInfo", {}).get("awayTeam", {}).get("scratches", None) if awayScratches is None: awayScratches = [] homeScratches = data["game"].get("matchup", {}).get("gameInfo", {}).get("homeTeam", {}).get("scratches", None) if not homeScratches: homeScratches = data["game"].get("summary", {}).get("gameInfo", {}).get("homeTeam", {}).get("scratches", None) + if not homeScratches: + homeScratches = data["game_right_rail"].get("gameInfo", {}).get("homeTeam", {}).get("scratches", None) if homeScratches is None: homeScratches = [] diff --git a/bots/nhl_game_threads/templates/skaters.mako b/bots/nhl_game_threads/templates/skaters.mako index feb264d..453e017 100644 --- a/bots/nhl_game_threads/templates/skaters.mako +++ b/bots/nhl_game_threads/templates/skaters.mako @@ -8,19 +8,19 @@ data["myTeam"] if data["homeAway"] == "home" else data["oppTeam"] ) - awayF = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("forwards", []) + awayF = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("forwards", []) awayL = [x for x in awayF if x["position"] == "L"] awayC = [x for x in awayF if x["position"] == "C"] awayR = [x for x in awayF if x["position"] == "R"] - awayD = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("defense", []) - awayG = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("awayTeam", {}).get("goalies", []) + awayD = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("defense", []) + awayG = data["game_boxscore"].get("playerByGameStats", {}).get("awayTeam", {}).get("goalies", []) awayOnIce = data["game_pbp"].get("awayTeam", {}).get("onIce", []) - homeF = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("forwards", []) + homeF = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("forwards", []) homeL = [x for x in homeF if x["position"] == "L"] homeC = [x for x in homeF if x["position"] == "C"] homeR = [x for x in homeF if x["position"] == "R"] - homeD = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("defense", []) - homeG = data["game_boxscore"].get("boxscore", {}).get("playerByGameStats", {}).get("homeTeam", {}).get("goalies", []) + homeD = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("defense", []) + homeG = data["game_boxscore"].get("playerByGameStats", {}).get("homeTeam", {}).get("goalies", []) homeOnIce = data["game_pbp"].get("homeTeam", {}).get("onIce", []) def playerLink(p): return f"[{p['name']['default']}](https://www.nhl.com/player/{p['playerId']})" diff --git a/redball/version.py b/redball/version.py index 484d35d..5309c31 100644 --- a/redball/version.py +++ b/redball/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "2024.10.5" +VERSION = "2024.10.6" From ac8c52d96e567fb775d3440781e73549154080d0 Mon Sep 17 00:00:00 2001 From: todd Date: Sat, 26 Oct 2024 20:20:21 -0400 Subject: [PATCH 3/4] fix: pinned praw to 7.7.1 due to token_manager missing in 7.8.1 ver(platform): 2024.10.7 --- redball/version.py | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/redball/version.py b/redball/version.py index 5309c31..a458b45 100644 --- a/redball/version.py +++ b/redball/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "2024.10.6" +VERSION = "2024.10.7" diff --git a/requirements.txt b/requirements.txt index 4b2c9da..649cac5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ requests apscheduler pytz tzlocal<3 -praw +praw<=7.7.1 mlb-statsapi pyOpenSSL mako From 43737ad91fb909e830a7f699b0d977417ae6a584 Mon Sep 17 00:00:00 2001 From: todd Date: Sat, 26 Oct 2024 20:24:57 -0400 Subject: [PATCH 4/4] fix: praw token manager import change for latest version ver(platform): 2024.10.6 --- redball/config.py | 3 ++- redball/version.py | 2 +- requirements.txt | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/redball/config.py b/redball/config.py index 353f741..76ec9fb 100644 --- a/redball/config.py +++ b/redball/config.py @@ -2,6 +2,7 @@ import json import praw +from praw.util.token_manager import BaseTokenManager from threading import Lock import uuid @@ -714,7 +715,7 @@ def callBack_redditAuth(state, code): return False -class RedditAuthDBTokenManager(praw.util.token_manager.BaseTokenManager): +class RedditAuthDBTokenManager(BaseTokenManager): def __init__(self, redditAuthId): super().__init__() self._reddit_auth_id = redditAuthId diff --git a/redball/version.py b/redball/version.py index a458b45..5309c31 100644 --- a/redball/version.py +++ b/redball/version.py @@ -1,3 +1,3 @@ #!/usr/bin/env python -VERSION = "2024.10.7" +VERSION = "2024.10.6" diff --git a/requirements.txt b/requirements.txt index 649cac5..4b2c9da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ requests apscheduler pytz tzlocal<3 -praw<=7.7.1 +praw mlb-statsapi pyOpenSSL mako