Update main.py

This commit is contained in:
Cal Corum 2023-04-30 22:41:18 -05:00
parent 2dc12d352e
commit 90098eb60c

51
main.py
View File

@ -1939,7 +1939,7 @@ class PackModel(pydantic.BaseModel):
async def v1_packs_get(
team_id: Optional[int] = None, pack_type_id: Optional[int] = None, opened: Optional[bool] = None,
limit: Optional[int] = None, new_to_old: Optional[bool] = None, pack_team_id: Optional[int] = None,
pack_cardset_id: Optional[int] = None, csv: Optional[bool] = None):
pack_cardset_id: Optional[int] = None, exact_match: Optional[bool] = False, csv: Optional[bool] = None):
all_packs = Pack.select()
if all_packs.count() == 0:
@ -1960,6 +1960,7 @@ async def v1_packs_get(
db.close()
raise HTTPException(status_code=404, detail=f'No pack type found with id {pack_type_id}')
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_team_id)
@ -1967,6 +1968,9 @@ async def v1_packs_get(
db.close()
raise HTTPException(status_code=404, detail=f'No team found with id {pack_team_id}')
all_packs = all_packs.where(Pack.pack_team == this_pack_team)
elif exact_match:
all_packs = all_packs.where(Pack.pack_team == None)
if pack_cardset_id is not None:
try:
this_pack_cardset = Cardset.get_by_id(pack_cardset_id)
@ -1974,6 +1978,9 @@ async def v1_packs_get(
db.close()
raise HTTPException(status_code=404, detail=f'No cardset found with id {pack_cardset_id}')
all_packs = all_packs.where(Pack.pack_cardset == this_pack_cardset)
elif exact_match:
all_packs = all_packs.where(Pack.pack_cardset == None)
if opened is not None:
all_packs = all_packs.where(Pack.open_time.is_null(not opened))
if limit is not None:
@ -2329,6 +2336,29 @@ async def v1_cards_ai_update(token: str = Depends(oauth2_scheme)):
raise HTTPException(status_code=200, detail=f'Just sent AI cards to sheets')
@app.post('/api/v1/cards/legal-check/{rarity_name}')
async def v1_cards_legal_check(
rarity_name: str, card_id: list = Query(default=None), token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning(f'Bad Token: {token}')
db.close()
raise HTTPException(
status_code=401,
detail='Unauthorized'
)
if rarity_name not in ['ranked']:
return f'Rarity name {rarity_name} not a valid check'
bad_cards = []
all_cards = Card.select().where(Card.id << card_id)
for x in all_cards:
if x.player.cardset_id not in [3, 4, 9, 10]:
bad_cards.append(x.player.description)
return {'count': len(bad_cards), 'bad_cards': bad_cards}
@app.post('/api/v1/cards/post-update/{starting_id}')
async def v1_cards_post_update(starting_id: int, token: str = Depends(oauth2_scheme)):
if not valid_token(token):
@ -4835,3 +4865,22 @@ async def v1_gauntletrun_delete(gauntletrun_id):
return f'Deleted gauntlet run ID {gauntletrun_id}'
raise DatabaseError(f'Unable to delete gauntlet run {gauntletrun_id}')
@app.post('/api/v1/stl-fix')
async def v1_stl_fix(token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning(f'Bad Token: {token}')
db.close()
raise HTTPException(
status_code=401,
detail='You are not authorized to post. This event has been logged.'
)
p_query = Player.update(mlbclub='St Louis Cardinals', franchise='St Louis Cardinals').where(
Player.mlbclub == 'St. Louis Cardinals'
).execute()
db.close()
return {'detail': f'Removed the period from St Louis'}