Update main.py
add players/random customization, fixed /packs team_id bug
This commit is contained in:
parent
8c7b5467dc
commit
35aae7fcc1
24
main.py
24
main.py
@ -1298,7 +1298,8 @@ async def v1_players_get_random(
|
||||
min_cost: Optional[int] = None, max_cost: Optional[int] = None, in_packs: Optional[bool] = True,
|
||||
min_rarity: Optional[int] = None, max_rarity: Optional[int] = None, limit: Optional[int] = None,
|
||||
pos_include: Optional[str] = None, pos_exclude: Optional[str] = None, franchise: Optional[str] = None,
|
||||
mlbclub: Optional[str] = None, csv: Optional[bool] = None):
|
||||
mlbclub: Optional[str] = None, cardset_id: list = Query(default=None), pos_inc: list = Query(default=None),
|
||||
pos_exc: list = Query(default=None), csv: Optional[bool] = None):
|
||||
all_players = (Player
|
||||
.select()
|
||||
.join(Cardset)
|
||||
@ -1328,11 +1329,26 @@ async def v1_players_get_random(
|
||||
all_players = all_players.where(fn.Lower(Player.franchise) == franchise.lower())
|
||||
if mlbclub is not None:
|
||||
all_players = all_players.where(fn.Lower(Player.mlbclub) == mlbclub.lower())
|
||||
if cardset_id is not None:
|
||||
all_players = all_players.where(Player.cardset_id << cardset_id)
|
||||
if pos_inc is not None:
|
||||
p_list = [x.upper() for x in pos_inc]
|
||||
all_players = all_players.where(
|
||||
(Player.pos_1 << p_list) | (Player.pos_2 << p_list) | (Player.pos_3 << p_list) | (Player.pos_4 << p_list) |
|
||||
(Player.pos_5 << p_list) | (Player.pos_6 << p_list) | (Player.pos_7 << p_list) | (Player.pos_8 << p_list)
|
||||
)
|
||||
if pos_exc is not None:
|
||||
p_list = [x.upper() for x in pos_exc]
|
||||
all_players = all_players.where(
|
||||
(Player.pos_1.not_in(p_list)) | (Player.pos_2.not_in(p_list)) | (Player.pos_3.not_in(p_list)) |
|
||||
(Player.pos_4.not_in(p_list)) | (Player.pos_5.not_in(p_list)) | (Player.pos_6.not_in(p_list)) |
|
||||
(Player.pos_7.not_in(p_list)) | (Player.pos_8.not_in(p_list))
|
||||
)
|
||||
|
||||
if pos_exclude:
|
||||
if pos_exclude is not None and pos_exc is None:
|
||||
final_players = [x for x in all_players if pos_exclude not in x.get_all_pos()]
|
||||
else:
|
||||
final_players = [x for x in all_players]
|
||||
final_players = all_players
|
||||
|
||||
if limit is not None:
|
||||
final_players = final_players[:limit]
|
||||
@ -1916,7 +1932,7 @@ async def v1_packs_get(
|
||||
all_packs = all_packs.where(Pack.pack_type == this_pack_type)
|
||||
if pack_team_id is not None:
|
||||
try:
|
||||
this_pack_team = Team.get_by_id(pack_type_id)
|
||||
this_pack_team = Team.get_by_id(pack_team_id)
|
||||
except Exception:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'No team found with id {pack_team_id}')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user