From 979bf357689ddf3199de6966c95dd6be389832a6 Mon Sep 17 00:00:00 2001 From: DMcP89 Date: Thu, 17 Oct 2024 22:28:17 -0400 Subject: [PATCH 1/4] limiting stats to array to 20 fields --- harambot/yahoo_api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/harambot/yahoo_api.py b/harambot/yahoo_api.py index b64a34b..680a9c7 100644 --- a/harambot/yahoo_api.py +++ b/harambot/yahoo_api.py @@ -185,11 +185,15 @@ def get_player_details(self, player_name, guild_id, week=None): player = self.league().player_details(player_name)[0] player["owner"] = self.get_player_owner(player["player_id"]) if week: - player["stats"] = self.league().player_stats( + stats = self.league().player_stats( [player["player_id"]], req_type="week", week=week, )[0] + if len(stats) > 25: + player["stats"] = stats[:20] + else: + player["stats"] = stats else: player["stats"] = self.league().player_stats( [player["player_id"]], From 4ddba64d0862dbc071b13aba585bb37c2fbf1f58 Mon Sep 17 00:00:00 2001 From: DMcP89 Date: Thu, 17 Oct 2024 23:21:33 -0400 Subject: [PATCH 2/4] Fixing issue with stats in NHL leagues --- harambot/cogs/yahoo.py | 20 +++++++++++--------- harambot/yahoo_api.py | 12 +++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/harambot/cogs/yahoo.py b/harambot/cogs/yahoo.py index 3e36106..28d09a7 100644 --- a/harambot/cogs/yahoo.py +++ b/harambot/cogs/yahoo.py @@ -141,7 +141,9 @@ async def trade(self, interaction: discord.Interaction): player_set0.append(player["name"]) api_details = ( self.get_player_text( - self.yahoo_api.get_player_details(player["name"], guild_id=interaction.guild_id) + self.yahoo_api.get_player_details( + player["name"], guild_id=interaction.guild_id + ) ) + "\n" ) @@ -155,7 +157,9 @@ async def trade(self, interaction: discord.Interaction): player_set1_details = "" for player in latest_trade["tradee_players"]: player_set1.append(player["name"]) - player_details = self.yahoo_api.get_player_details(player["name"], guild_id=interaction.guild_id) + player_details = self.yahoo_api.get_player_details( + player["name"], guild_id=interaction.guild_id + ) if player_details is None: await interaction.followup.send(self.error_message) return @@ -267,13 +271,11 @@ def get_player_embed(self, player): value=player["stats"]["total_points"], inline=False, ) - del player["stats"]["player_id"] - del player["stats"]["name"] - del player["stats"]["position_type"] - for key, value in player["stats"].items(): - if key == "total_points": - continue - embed.add_field(name=key, value=value) + if len(player["stats"].items()) < 20: + for key, value in player["stats"].items(): + if key == "total_points": + continue + embed.add_field(name=key, value=value) return embed def get_player_text(self, player): diff --git a/harambot/yahoo_api.py b/harambot/yahoo_api.py index 680a9c7..41562f8 100644 --- a/harambot/yahoo_api.py +++ b/harambot/yahoo_api.py @@ -190,15 +190,17 @@ def get_player_details(self, player_name, guild_id, week=None): req_type="week", week=week, )[0] - if len(stats) > 25: - player["stats"] = stats[:20] - else: - player["stats"] = stats else: - player["stats"] = self.league().player_stats( + stats = self.league().player_stats( [player["player_id"]], req_type="season", )[0] + del stats["player_id"] + del stats["name"] + del stats["position_type"] + if len(stats) > 20: + stats = {k: v for k, v in stats.items() if v != 0.0} + player["stats"] = stats return player except Exception: logger.exception( From 34ccc74f0786118638004d5860ba740e4bc11631 Mon Sep 17 00:00:00 2001 From: DMcP89 Date: Thu, 17 Oct 2024 23:28:49 -0400 Subject: [PATCH 3/4] Fixing tests --- tests/conftest.py | 9 ++++++++- tests/test-player-details.json | 27 ++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b78cfb5..2bc3926 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,7 +45,14 @@ def mock_player_details(): @pytest.fixture def mock_player_stats(): - return [{"mock": "stats"}] + return [ + { + "mock": "stats", + "player_id": "39077", + "name": "Josh Allen", + "position_type": "o", + } + ] @pytest.fixture diff --git a/tests/test-player-details.json b/tests/test-player-details.json index 64335bb..94a3d6f 100644 --- a/tests/test-player-details.json +++ b/tests/test-player-details.json @@ -34,7 +34,32 @@ "coverage_type": "season", "season": "2020" }, - "stats": [{ + "stats": [ + { + "stat": { + "stat_id": "0", + "value": "396" + } + }, + { + "stat": { + "stat_id": "1", + "value": "572" + } + }, + { + "stat": { + "stat_id": "2", + "value": "4544" + } + }, + { + "stat": { + "stat_id": "3", + "value": "37" + } + }, + { "stat": { "stat_id": "4", "value": "2871" From 59afb9b60a890843a9ecc96b7001d14af267ecb2 Mon Sep 17 00:00:00 2001 From: DMcP89 Date: Mon, 21 Oct 2024 12:21:32 -0400 Subject: [PATCH 4/4] bumping version --- README.md | 2 +- pyproject.toml | 2 +- render.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 43b2682..ba24eb7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Harambot _An interactive Yahoo Fantasy sports bot for Discord._ -![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/actions/workflow/status/DMcP89/harambot/unit-tests.yml?branch=main) ![Version](https://img.shields.io/badge/version-0.4.2--Beta-red) +![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/actions/workflow/status/DMcP89/harambot/unit-tests.yml?branch=main) ![Version](https://img.shields.io/badge/version-0.4.4--Beta-red) diff --git a/pyproject.toml b/pyproject.toml index c1e4dc3..c421d3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "harambot" -version = "0.4.3" +version = "0.4.4" description = "A Yahoo Fantasy Sports bot for Discord" authors = ["DMcP89 "] license = "MIT" diff --git a/render.yaml b/render.yaml index f30f567..bb70c48 100644 --- a/render.yaml +++ b/render.yaml @@ -44,7 +44,7 @@ services: - key: RUN_MIGRATIONS sync: false - key: VERSION - value: "0.4.3-Beta" + value: "0.4.4-Beta" databases: - name: harambot-database