From 878e2889ab3b1b2c383f95d3a56e082c7c8a9ddc Mon Sep 17 00:00:00 2001 From: indigobuffalo Date: Fri, 17 Jan 2025 20:27:17 -0800 Subject: [PATCH 1/4] make Team updates --- yahoo_fantasy_api/team.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/yahoo_fantasy_api/team.py b/yahoo_fantasy_api/team.py index 6aaa6fe..2f16ba7 100644 --- a/yahoo_fantasy_api/team.py +++ b/yahoo_fantasy_api/team.py @@ -149,6 +149,19 @@ def add_player(self, player_id): xml = self._construct_transaction_xml("add", player_id) self.yhandler.post_transactions(self.league_id, xml) + def claim_player(self, player_id, faab=None): + """Claim a single player from waivers by their player ID + + :param player_id: Yahoo! player ID of the player to add + :type player_id: int + :param faab: Number of faab dollars to bid on the claim + :type faab: int + + >>> tm.add_player(6767, faab=7) + """ + xml = self._construct_transaction_xml("add", player_id, faab=faab) + self.yhandler.post_transactions(self.league_id, xml) + def drop_player(self, player_id): """Drop a single player by their player ID @@ -174,6 +187,23 @@ def add_and_drop_players(self, add_player_id, drop_player_id): drop_player_id) self.yhandler.post_transactions(self.league_id, xml) + def claim_and_drop_players(self, add_player_id, drop_player_id, faab=None): + """Claim one player from waivers and drop another in the same transaction + + :param add_player_id: Yahoo! player ID of the player to add + :type add_player_id: int + :param drop_player_id: Yahoo! player ID of the player to drop + :type drop_player_id: int + :param faab: Number of faab dollars to bid on the claim + :type faab: int + + >>> tm.claim_and_drop_players(6770, 6767, faab=22) + """ + xml = self._construct_transaction_xml( + "add/drop", add_player_id, drop_player_id, faab=faab + ) + self.yhandler.post_transactions(self.league_id, xml) + def proposed_trades(self): """ Retrieve information for any proposed trades that include your team @@ -408,13 +438,18 @@ def _construct_change_roster_xml(self, time_frame, modified_lineup): return doc.toprettyxml() - def _construct_transaction_xml(self, action, *player_ids): + def _construct_transaction_xml(self, action, *player_ids, faab=None): doc = Document() transaction = doc.appendChild(doc.createElement('fantasy_content')) \ .appendChild(doc.createElement('transaction')) transaction.appendChild(doc.createElement('type')) \ .appendChild(doc.createTextNode(action)) + + if faab is not None: + transaction.appendChild(doc.createElement("faab_bid")) \ + .appendChild(doc.createTextNode(str(faab))) + if action == 'add/drop': players = transaction.appendChild(doc.createElement('players')) self._construct_transaction_player_xml(doc, players, player_ids[0], From 9b2e7e450ab59b0667d53a36b2f173a7ae1a0fad Mon Sep 17 00:00:00 2001 From: indigobuffalo Date: Fri, 17 Jan 2025 21:13:54 -0800 Subject: [PATCH 2/4] add tests --- yahoo_fantasy_api/tests/test_team.py | 39 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/yahoo_fantasy_api/tests/test_team.py b/yahoo_fantasy_api/tests/test_team.py index f9ea88a..daedd02 100644 --- a/yahoo_fantasy_api/tests/test_team.py +++ b/yahoo_fantasy_api/tests/test_team.py @@ -5,6 +5,8 @@ import pytest +DIR_PATH = os.path.dirname(os.path.realpath(__file__)) + def test_matchup(mock_team): opponent = mock_team.matchup(3) assert(opponent == '388.l.27081.t.5') @@ -58,8 +60,7 @@ def test_proposed_trades(mock_team): def test__construct_trade_xml(mock_team): - dir_path = os.path.dirname(os.path.realpath(__file__)) - with open(f'{dir_path}/accept_trade.xml', 'r') as file: + with open(f'{DIR_PATH}/accept_trade.xml', 'r') as file: expected_xml = file.read().replace(' ', '\t') transaction_key = '396.l.49770.pt.1' @@ -69,8 +70,7 @@ def test__construct_trade_xml(mock_team): def test__construct_trade_proposal_xml(mock_team): - dir_path = os.path.dirname(os.path.realpath(__file__)) - with open(f'{dir_path}/trade_proposal.xml', 'r') as file: + with open(f'{DIR_PATH}/trade_proposal.xml', 'r') as file: expected_xml = file.read().replace(' ', '\t') tradee_team_key = '248.l.55438.t.4' @@ -84,6 +84,37 @@ def test__construct_trade_proposal_xml(mock_team): assert actual_xml == expected_xml +def test__construct_transaction_xml(mock_team): + with open(f'{DIR_PATH}/add_drop_with_faab.xml', 'r') as file: + expected_xml = file.read().replace(' ', '\t') + + action = "add/drop" + add_player_id=123 + drop_player_id=456 + faab = 99 + + actual_xml = mock_team._construct_transaction_xml( + action, add_player_id, drop_player_id, faab=faab + ) + + assert actual_xml == expected_xml + + +def test__construct_transaction_xml_with_faab(mock_team): + with open(f'{DIR_PATH}/add_drop_no_faab.xml', 'r') as file: + expected_xml = file.read().replace(' ', '\t') + + action = "add/drop" + add_player_id=123 + drop_player_id=456 + + actual_xml = mock_team._construct_transaction_xml( + action, add_player_id, drop_player_id + ) + + assert actual_xml == expected_xml + + def test_change_roster(mock_team): plyrs = [{'player_id': 5981, 'selected_position': 'BN'}, {'player_id': 4558, 'selected_position': 'BN'}] From eb1cbf1308ba62c34ca6908b44fd5240056014a5 Mon Sep 17 00:00:00 2001 From: indigobuffalo Date: Sun, 19 Jan 2025 13:25:17 -0800 Subject: [PATCH 3/4] bump version, adding missing stubs --- setup.py | 2 +- yahoo_fantasy_api/tests/add_drop_no_faab.xml | 22 ++++++++++++++++++ .../tests/add_drop_with_faab.xml | 23 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 yahoo_fantasy_api/tests/add_drop_no_faab.xml create mode 100644 yahoo_fantasy_api/tests/add_drop_with_faab.xml diff --git a/setup.py b/setup.py index f4864ab..5b591ce 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def readme(): setup(name='yahoo_fantasy_api', - version='2.9.1', + version='2.10.0', description='Python bindings to access the Yahoo! Fantasy APIs', long_description=readme(), url='http://github.com/spilchen/yahoo_fantasy_api', diff --git a/yahoo_fantasy_api/tests/add_drop_no_faab.xml b/yahoo_fantasy_api/tests/add_drop_no_faab.xml new file mode 100644 index 0000000..fba5166 --- /dev/null +++ b/yahoo_fantasy_api/tests/add_drop_no_faab.xml @@ -0,0 +1,22 @@ + + + + add/drop + + + 268.p.123 + + add + 268.l.46645 + + + + 268.p.456 + + drop + 268.l.46645 + + + + + diff --git a/yahoo_fantasy_api/tests/add_drop_with_faab.xml b/yahoo_fantasy_api/tests/add_drop_with_faab.xml new file mode 100644 index 0000000..3471e7c --- /dev/null +++ b/yahoo_fantasy_api/tests/add_drop_with_faab.xml @@ -0,0 +1,23 @@ + + + + add/drop + 99 + + + 268.p.123 + + add + 268.l.46645 + + + + 268.p.456 + + drop + 268.l.46645 + + + + + From 6b5ffa329a252bb3a837ebf831b219eab128aacd Mon Sep 17 00:00:00 2001 From: indigobuffalo Date: Sun, 19 Jan 2025 13:31:05 -0800 Subject: [PATCH 4/4] nit: update docstring wording --- yahoo_fantasy_api/team.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yahoo_fantasy_api/team.py b/yahoo_fantasy_api/team.py index 2f16ba7..ff61ca7 100644 --- a/yahoo_fantasy_api/team.py +++ b/yahoo_fantasy_api/team.py @@ -150,7 +150,7 @@ def add_player(self, player_id): self.yhandler.post_transactions(self.league_id, xml) def claim_player(self, player_id, faab=None): - """Claim a single player from waivers by their player ID + """Submit a waiver claim for a single player by their player ID :param player_id: Yahoo! player ID of the player to add :type player_id: int @@ -188,7 +188,7 @@ def add_and_drop_players(self, add_player_id, drop_player_id): self.yhandler.post_transactions(self.league_id, xml) def claim_and_drop_players(self, add_player_id, drop_player_id, faab=None): - """Claim one player from waivers and drop another in the same transaction + """Submit a waiver claim for one player and drop another in the same transaction :param add_player_id: Yahoo! player ID of the player to add :type add_player_id: int