Add CLI args for host, port, workers, and reload
This commit is contained in:
parent
20dca2eefa
commit
ff29a3cd4e
@ -20,6 +20,7 @@ app = FastAPI(title="Chess Pressure", docs_url=None, redoc_url=None)
|
|||||||
|
|
||||||
# --- Models ---
|
# --- Models ---
|
||||||
|
|
||||||
|
|
||||||
class PGNUpload(BaseModel):
|
class PGNUpload(BaseModel):
|
||||||
pgn: str
|
pgn: str
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ class MoveRequest(BaseModel):
|
|||||||
|
|
||||||
# --- API ---
|
# --- API ---
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/games")
|
@app.get("/api/games")
|
||||||
def list_games():
|
def list_games():
|
||||||
return get_game_list()
|
return get_game_list()
|
||||||
@ -55,6 +57,7 @@ def parse_uploaded_pgn(body: PGNUpload):
|
|||||||
@app.get("/api/legal")
|
@app.get("/api/legal")
|
||||||
def legal_moves(fen: str):
|
def legal_moves(fen: str):
|
||||||
import chess
|
import chess
|
||||||
|
|
||||||
board = chess.Board(fen)
|
board = chess.Board(fen)
|
||||||
return [m.uci() for m in board.legal_moves]
|
return [m.uci() for m in board.legal_moves]
|
||||||
|
|
||||||
@ -81,7 +84,28 @@ def index():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
uvicorn.run("chess_pressure.app:app", host="0.0.0.0", port=8888, workers=2)
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Chess Pressure server")
|
||||||
|
parser.add_argument(
|
||||||
|
"--host", default="0.0.0.0", help="Bind address (default: 0.0.0.0)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--port", "-p", type=int, default=8888, help="Port (default: 8888)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--workers", "-w", type=int, default=2, help="Worker processes (default: 2)"
|
||||||
|
)
|
||||||
|
parser.add_argument("--reload", action="store_true", help="Enable auto-reload")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
uvicorn.run(
|
||||||
|
"chess_pressure.app:app",
|
||||||
|
host=args.host,
|
||||||
|
port=args.port,
|
||||||
|
workers=args.workers,
|
||||||
|
reload=args.reload,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -64,26 +64,32 @@ def parse_pgn(pgn_text: str) -> dict:
|
|||||||
frames = []
|
frames = []
|
||||||
|
|
||||||
# Frame 0: starting position
|
# Frame 0: starting position
|
||||||
frames.append({
|
frames.append(
|
||||||
|
{
|
||||||
"board": board_to_dict(board),
|
"board": board_to_dict(board),
|
||||||
"pressure": compute_pressure(board, weighted=False),
|
"pressure": compute_pressure(board, weighted=False),
|
||||||
"pressure_weighted": compute_pressure(board, weighted=True),
|
"pressure_weighted": compute_pressure(board, weighted=True),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for node in game.mainline():
|
for node in game.mainline():
|
||||||
move = node.move
|
move = node.move
|
||||||
san = board.san(move)
|
san = board.san(move)
|
||||||
board.push(move)
|
board.push(move)
|
||||||
moves.append({
|
moves.append(
|
||||||
|
{
|
||||||
"san": san,
|
"san": san,
|
||||||
"uci": move.uci(),
|
"uci": move.uci(),
|
||||||
"ply": board.ply(),
|
"ply": board.ply(),
|
||||||
})
|
}
|
||||||
frames.append({
|
)
|
||||||
|
frames.append(
|
||||||
|
{
|
||||||
"board": board_to_dict(board),
|
"board": board_to_dict(board),
|
||||||
"pressure": compute_pressure(board, weighted=False),
|
"pressure": compute_pressure(board, weighted=False),
|
||||||
"pressure_weighted": compute_pressure(board, weighted=True),
|
"pressure_weighted": compute_pressure(board, weighted=True),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"headers": headers,
|
"headers": headers,
|
||||||
|
|||||||
@ -198,7 +198,10 @@ Ke7 29.Ra1 Nc6 0-1""",
|
|||||||
|
|
||||||
def get_game_list() -> list[dict]:
|
def get_game_list() -> list[dict]:
|
||||||
"""Return list of available games (id, name, white, black)."""
|
"""Return list of available games (id, name, white, black)."""
|
||||||
return [{"id": g["id"], "name": g["name"], "white": g["white"], "black": g["black"]} for g in GAMES]
|
return [
|
||||||
|
{"id": g["id"], "name": g["name"], "white": g["white"], "black": g["black"]}
|
||||||
|
for g in GAMES
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_game_pgn(game_id: str) -> str | None:
|
def get_game_pgn(game_id: str) -> str | None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user