Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basketball League Transactions #598

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions espn_api/basketball/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .box_score import get_box_scoring_type_class, BoxScore
from .constant import PRO_TEAM_MAP
from .activity import Activity
from .transaction import Transaction
from .constant import POSITION_MAP, ACTIVITY_MAP

class League(BaseLeague):
Expand Down Expand Up @@ -104,6 +105,21 @@

return activity

def transactions(self, scoring_period: int = None) -> List[Transaction]:
'''Returns a list of recent transactions'''
params = {

Check warning on line 110 in espn_api/basketball/league.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/league.py#L110

Added line #L110 was not covered by tests
'view': 'mTransactions2',
'scoringPeriodId': scoring_period,
cwendt94 marked this conversation as resolved.
Show resolved Hide resolved
}

filters = {"transactions":{"filterType":{"value":["FREEAGENT","WAIVER","WAIVER_ERROR"]}}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having these filter types as default is good and then allow it to be passed in to the function as well in case you only want to look for one or different ones.

headers = {'x-fantasy-filter': json.dumps(filters)}

Check warning on line 116 in espn_api/basketball/league.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/league.py#L115-L116

Added lines #L115 - L116 were not covered by tests

data = self.espn_request.league_get(params=params, headers=headers)
transactions = data['transactions']

Check warning on line 119 in espn_api/basketball/league.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/league.py#L118-L119

Added lines #L118 - L119 were not covered by tests

return [Transaction(transaction, self.player_map, self.get_team_data) for transaction in transactions]

Check warning on line 121 in espn_api/basketball/league.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/league.py#L121

Added line #L121 was not covered by tests

def free_agents(self, week: int=None, size: int=50, position: str=None, position_id: int=None) -> List[Player]:
'''Returns a List of Free Agents for a Given Week\n
Should only be used with most recent season'''
Expand Down
17 changes: 17 additions & 0 deletions espn_api/basketball/transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .transaction_item import TransactionItem

class Transaction(object):
def __init__(self, data, player_map, get_team_data):
self.team = get_team_data(data['teamId'])
self.type = data['type']
self.status = data['status']
self.scoring_period = data['scoringPeriodId']
self.date = data['processDate']
self.bid_amount = data['bidAmount']
self.items = []
for item in data['items']:
self.items.append(TransactionItem(item, player_map))

Check warning on line 13 in espn_api/basketball/transaction.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/transaction.py#L5-L13

Added lines #L5 - L13 were not covered by tests

def __repr__(self):
items = ', '.join([str(item) for item in self.items])
return f'Transaction({self.team.team_name} {self.type} {items})'

Check warning on line 17 in espn_api/basketball/transaction.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/transaction.py#L16-L17

Added lines #L16 - L17 were not covered by tests
7 changes: 7 additions & 0 deletions espn_api/basketball/transaction_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TransactionItem(object):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be better defined in the same file as transactions

def __init__(self, data, player_map):
self.type = data['type']
self.player = player_map[data['playerId']]

Check warning on line 4 in espn_api/basketball/transaction_item.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/transaction_item.py#L3-L4

Added lines #L3 - L4 were not covered by tests

def __repr__(self):
return f'{self.type} {self.player}'

Check warning on line 7 in espn_api/basketball/transaction_item.py

View check run for this annotation

Codecov / codecov/patch

espn_api/basketball/transaction_item.py#L7

Added line #L7 was not covered by tests
Loading