paper-dynasty-database/app/routers_v2/scouting.py
Cal Corum 7b494faa99 fix: remove broken live_update_batting stub endpoint (#10)
The endpoint iterated over `files.vl_basic` (a string, not parsed CSV),
causing it to loop over individual characters. The body contained only
`pass` with TODO comments and no running stats logic. Removed the
endpoint entirely along with the dead commented-out csv helper code.
The `BattingFiles` model is retained as it is still used by
`live_update_pitching`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-05 15:34:06 -06:00

50 lines
1.5 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Query
import logging
import pydantic
from ..db_engine import Player
from ..dependencies import oauth2_scheme, valid_token
from ..player_scouting import get_player_ids
router = APIRouter(prefix="/api/v2/scouting", tags=["scouting"])
class BattingFiles(pydantic.BaseModel):
vl_basic: str = "vl-basic.csv"
vl_rate: str = "vl-rate.csv"
vr_basic: str = "vr-basic.csv"
vr_rate: str = "vr-rate.csv"
running: str = "running.csv"
# def csv_file_to_dataframe(filename: str) -> pd.DataFrame | None:
# with open(filename, 'r', encoding='utf8') as file:
# reader = csv.reader(file)
#
# for row in reader:
@router.get("/playerkeys")
async def get_player_keys(player_id: list = Query(default=None)):
all_keys = []
for x in player_id:
this_player = Player.get_or_none(Player.player_id == x)
if this_player is not None:
this_keys = get_player_ids(this_player.bbref_id, id_type="bbref")
if this_keys is not None:
all_keys.append(this_keys)
return_val = {"count": len(all_keys), "keys": [dict(x) for x in all_keys]}
return return_val
@router.post("/live-update/pitching")
def live_update_pitching(files: BattingFiles, token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning("Bad Token: [REDACTED]")
raise HTTPException(
status_code=401, detail="You are not authorized to initiate live updates."
)
return files.dict()