add a script to stream a lichess game using the FEN tty output - chess-puzzles … | |
git clone git://git.codemadness.org/chess-puzzles | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit d3c8592f3761018e4fac3ba37503f432cb1dda1f | |
parent 528629a967639e013c56fee9c293b7b87376d15e | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Thu, 21 Dec 2023 00:24:03 +0100 | |
add a script to stream a lichess game using the FEN tty output | |
Diffstat: | |
A docs/stream_lichess.sh | 33 +++++++++++++++++++++++++++++… | |
1 file changed, 33 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/docs/stream_lichess.sh b/docs/stream_lichess.sh | |
@@ -0,0 +1,33 @@ | |
+#!/bin/sh | |
+# Stream a lichess game, by game id. | |
+# Requires permissions to the board / game. | |
+# NOTE that it updates after a move. | |
+# Dependencies: curl, json2tsv (could be replaced by jq). | |
+ | |
+if [ "$1" = "" ]; then | |
+ echo "Usage: $0 <gameid>" >&2 | |
+ exit 1 | |
+fi | |
+ | |
+gameid="$1" | |
+token="API token here" | |
+ | |
+url="https://lichess.org/api/board/game/stream/$gameid" | |
+ | |
+# start position | |
+fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" | |
+ | |
+# -N disables cURL buffering, each line is streamed as JSON. | |
+curl \ | |
+-f \ | |
+-s \ | |
+-N \ | |
+-H "Authorization: Bearer $token" \ | |
+-H 'Accept: application/x-ndjson' "$url" | \ | |
+while read -r json; do | |
+ moves=$(printf '%s' "$json" | jaq '$1 == ".moves" { print $3; }') | |
+ test "$moves" = "" && continue | |
+ | |
+ clear | |
+ ./fen -o tty "$fen" "$moves" | |
+done |