Skip to content

Commit

Permalink
Add optional week param to team.change_positions() to use in NFL leagues
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaturensky committed Aug 14, 2024
1 parent 46526ce commit f3b8755
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions yahoo_fantasy_api/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,29 @@ def _compact_eligible_pos(j):
pass
return roster

def change_positions(self, day, modified_lineup):
def change_positions(self, modified_lineup, day=None, week=None):
"""Change the starting position of a subset of players in your lineup
This raises a RuntimeError if any error occurs when communicating with
Yahoo!
:param day: The day that the new positions take affect. This should be
the starting day of the week.
:type day: :class:`datetime.date`
:param modified_lineup: List of players to modify. Each entry should
have a dict with the following keys: player_id - player ID of the
player to change; selected_position - new position of the player.
:type modified_lineup: list(dict)
:param day: The day that the new positions take affect. This should be
the starting day of the week.
:type day: :class:`datetime.date`
:param week: Week number that the new positions take affect
:type week: int
>>>
import datetime
cd = datetime.date(2019, 10, 7)
plyrs = [{'player_id': 5981, 'selected_position': 'BN'},
{'player_id': 4558, 'selected_position': 'BN'}]
tm.change_positions(cd, plyrs)
tm.change_positions(plyrs, cd)
"""
xml = self._construct_change_roster_xml(day, modified_lineup)
xml = self._construct_change_roster_xml(modified_lineup, day, week)
self.yhandler.put_roster(self.team_key, xml)

def add_player(self, player_id):
Expand Down Expand Up @@ -377,16 +378,22 @@ def _construct_trade_proposal_xml(self, tradee_team_key: str, your_player_keys:

return doc.toprettyxml()

def _construct_change_roster_xml(self, day, modified_lineup):
def _construct_change_roster_xml(self, modified_lineup, day, week):
"""Construct XML to pass to Yahoo! that will modified the positions"""
doc = Document()
roster = doc.appendChild(doc.createElement('fantasy_content')) \
.appendChild(doc.createElement('roster'))

roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('date'))
roster.appendChild(doc.createElement('date')) \
.appendChild(doc.createTextNode(day.strftime("%Y-%m-%d")))

if week is not None:
roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('week'))
roster.appendChild(doc.createElement('week')) \
.appendChild(doc.createTextNode(str(week)))
else:
roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('date'))
roster.appendChild(doc.createElement('date')) \
.appendChild(doc.createTextNode(day.strftime("%Y-%m-%d")))

plyrs = roster.appendChild(doc.createElement('players'))
for plyr in modified_lineup:
Expand Down

0 comments on commit f3b8755

Please sign in to comment.