Skip to content

Commit

Permalink
josuebrunel#37 : Completed base code of editing waivers, allowing tra…
Browse files Browse the repository at this point in the history
…des. Adding to transactions GET. Testing to follow.
  • Loading branch information
peacing committed Jul 25, 2015
1 parent 29ff13a commit b18507b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
14 changes: 13 additions & 1 deletion fantasy_sport/fantasy_sport.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,19 @@ def get_transactions(self, transaction_keys, players=None):
response = self._get(uri)
return response

def edit_waivers(self, team_keys, transactions):
def get_all_completed_leagues_transactions(self, league_keys):
"""Return all transactions form multiple leagues
>>>yfs.get_all_completed_leagues_transactions(['league_key1', 'leaguekey2'])
"""

uri = self._build_uri('leagues;league_keys', league_keys, sub='transactions')
response = self._get(uri)
return response


### PUT Functions

def edit_waivers(self, transaction_keys, transactions):
"""
>>> from fantasy_sport import Roster, Player
>>> p1 = Player('242.p.8332','WR')
Expand Down
77 changes: 77 additions & 0 deletions fantasy_sport/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,81 @@ def json_builder(self, ):
}

return self.json


class Transaction(Base):
"""transaction class
- transaction_key
- type
-- edit waiver
- waiver_priority
- faab_bid
-- allow/disallow/vote against trades
- action
"""

def __init__(self, transaction_key, type, waiver_priority=None, faab_bid=None, action=None, trade_note=None, voter_team_key=None):
"""Initialize a Transaction object
"""
super(Base, self).__init()

self.transaction_key = transaction_key
self.type = type
self.waiver_priority = waiver_priority
self.faab_bid = faab_bid
self.action = action
self.trade_note = trade_note
self.voter_team_key = voter_team_key

self.xml_builder()
#self.json_builder()

def xml_builder(self,):
"""Convert object to xml
"""
content = ctree.Element('fantasy_content')
transaction = ctree.SubElement(content, 'transaction')

transaction_key = ctree.SubElement(transaction, 'transaction_key')
transaction_key.text = self.transaction_key

type = ctree.SubElement(transaction, 'type')
type.text = self.type

if waiver_priority:
waiver_priority = ctree.SubElement(transaction, 'waiver_priority')
waiver_priority.text = self.waiver_priority

if faab_bid:
faab_bid = ctree.SubElement(transaction, 'faab_bid')
faab_bid.text = self.faab_bid

if action:
action = ctree.SubElement(transaction, 'action')
action.text = self.action

if trade_note:
trade_note = ctree.SubElement(transaction, 'trade_note')
trade_note.text = self.trade_note

if voter_team_key:
voter_team_key = ctree.SubElement(transaction, 'voter_team_key')
voter_team_key.text = self.voter_team_key

self.xml = content

def json_builder(self,):
"""Convert object to json
"""
self.json = {
'fantasy_content':{
'roster':{
'coverage_type': self.coverage_type,
self.coverage_type : self.coverage,
'players': [ player.json for player in self.players ]
}
}
}
return self.json


This comment has been minimized.

Copy link
@josuebrunel

josuebrunel Jul 27, 2015

Awesome Paul, but i think we will drop out the _json_builder_ since it isn't supported by Yahoo ( which pitty though )

9 changes: 7 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,13 @@ def setUp(self,):
self.yfs = FantasySport(oauth)

def test_get_transactions(self,):
response = self.yfs.get_transactions(['346.l.1328.tr.100'], players='draft_analysis')
#logging.debug(pretty_json(response.content))
response = self.yfs.get_transactions(['346.l.1328.tr.100'], players=None)
logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

def test_get_all_completed_leagues_transactions(self,):
response = self.yfs.get_all_completed_leagues_transactions(['346.l.1328'])
logging.debug(pretty_json(response.content))
self.assertEqual(response.status_code, 200)

class TestFantasySportRoster(unittest.TestCase):
Expand Down

0 comments on commit b18507b

Please sign in to comment.