Skip to content

Commit

Permalink
Replace day with time_frame and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaturensky committed Aug 20, 2024
1 parent f3b8755 commit b211d1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def readme():


setup(name='yahoo_fantasy_api',
version='2.8.0',
version='2.9.0',
description='Python bindings to access the Yahoo! Fantasy APIs',
long_description=readme(),
url='http://github.com/spilchen/yahoo_fantasy_api',
Expand Down
31 changes: 16 additions & 15 deletions yahoo_fantasy_api/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from yahoo_fantasy_api import yhandler
import objectpath
import datetime
from xml.dom.minidom import Document

from yahoo_fantasy_api.utils import create_element
Expand Down Expand Up @@ -113,29 +114,27 @@ def _compact_eligible_pos(j):
pass
return roster

def change_positions(self, modified_lineup, day=None, week=None):
def change_positions(self, time_frame, modified_lineup):
"""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 time_frame: The time frame that the new positions take affect. This should be
the starting day of the week (MLB, NBA, or NHL) or the week number (NFL).
:type time_frame: :class:`datetime.date` | int
: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(plyrs, cd)
tm.change_positions(cd, plyrs)
"""
xml = self._construct_change_roster_xml(modified_lineup, day, week)
xml = self._construct_change_roster_xml(time_frame, modified_lineup)
self.yhandler.put_roster(self.team_key, xml)

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

return doc.toprettyxml()

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

if week is not None:
if isinstance(time_frame, datetime.date):
roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('date'))
roster.appendChild(doc.createElement('date')) \
.appendChild(doc.createTextNode(time_frame.strftime("%Y-%m-%d")))
elif isinstance(time_frame, int):
roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('week'))
roster.appendChild(doc.createElement('week')) \
.appendChild(doc.createTextNode(str(week)))
.appendChild(doc.createTextNode(str(time_frame)))
else:
roster.appendChild(doc.createElement('coverage_type')) \
.appendChild(doc.createTextNode('date'))
roster.appendChild(doc.createElement('date')) \
.appendChild(doc.createTextNode(day.strftime("%Y-%m-%d")))
raise RuntimeError("Invalid time_frame format")

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

0 comments on commit b211d1f

Please sign in to comment.