From 465c7646310a9dff64fc347edd0d3d9e112b6d44 Mon Sep 17 00:00:00 2001 From: Robert Perrotta Date: Sun, 3 Oct 2021 15:42:58 -0400 Subject: [PATCH] Add replay capability from file and from server --- reconchess_tools/cli/main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/reconchess_tools/cli/main.py b/reconchess_tools/cli/main.py index dd69853..dafb38e 100644 --- a/reconchess_tools/cli/main.py +++ b/reconchess_tools/cli/main.py @@ -1,6 +1,7 @@ import chess import click import reconchess +import requests from reconchess_tools.ui.replay import Replay @@ -30,5 +31,34 @@ def bot_match(white_path, black_path): Replay.from_history(history).play_sync() +@cli.command() +@click.argument("replay_path", type=str) +def replay_from_file(replay_path): + history = reconchess.GameHistory.from_file(replay_path) + Replay.from_history(history).play_sync() + + +@cli.command() +@click.argument("username") +@click.argument("password") +@click.argument("game_id", type=int) +@click.option( + "--server-url", + "server_url", + default="https://rbc.jhuapl.edu", + help="URL of the server.", +) +def replay_from_server(username, password, game_id, server_url): + response = requests.get( + server_url + f"/api/games/{game_id}/game_history", auth=(username, password) + ) + if response.status_code != 200: + raise requests.HTTPError(response.text) + history: reconchess.GameHistory = response.json(cls=reconchess.GameHistoryDecoder)[ + "game_history" + ] + Replay.from_history(history).play_sync() + + if __name__ == "__main__": cli()