Skip to content

A filter on the 'get_all_players()' method? #5

@chininhaNortao

Description

@chininhaNortao

Hello, I'm developing an application to gather the data of a league that I have, dynasty format, to facilitate the control of salaries, free agent and etc.

Starting by working with the 'get_all_players()' method, so that we can make a relationship with the team's players and whoever is not on a team, we will consider it as a free agent. It hasn't been put into practice yet haha

Having to do the data processing of this return, the api returns the coachs and defense teams, so I thought of “upgrading” the method, I've never done a PR in third-party code, so just commenting on it, the idea was with that, what do you think?

def get_all_players(self, type="all"):
    r = self._call("https://api.sleeper.app/v1/players/nfl")
    r_non_players = {_:r[_] for _ in r if r[_]['position'] == None}
    r_def_players = {_:r[_] for _ in r if r[_]['position'] == 'DEF'}
    r_only_players = {_:r[_] for _ in r if r[_]['position'] != None\
                                        and r[_]['position'] != "DEF"}

    player_type = {'all':r,
                   'only_players':r_only_players,
                   'def_players':r_def_players,
                   'non_players':r_non_players}

    return player_type[type]

I don't know how this would be in terms of performance and if it's within the pep8 standard, if it's positive and makes sense, think about filtering by positions too.

That's it, thanks for your attention, guys. #GoGiants

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions