Introduction
Introduction Statistics Contact Development Disclaimer Help
stream_lichess.sh: read initial FEN for chess960, show white vs black name - ch…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 4f6db6f748b3760f1f991e46bbb37246d201d4c8
parent aa7a4692fb14c40930fde876585a70a88b76b3e2
Author: Hiltjo Posthuma <[email protected]>
Date: Thu, 21 Dec 2023 22:45:17 +0100
stream_lichess.sh: read initial FEN for chess960, show white vs black name
Diffstat:
M TODO | 3 ---
M docs/stream_lichess.sh | 22 ++++++++++++++++++++--
2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/TODO b/TODO
@@ -1,6 +1,3 @@
-- stream_lichess.sh: lichess API: read FEN of start position, for chess 960
-chess variant.
-
- option for output for annotating moves in a human-like way (for screenreader…
https://en.wikipedia.org/wiki/Portable_Game_Notation
PGN:
diff --git a/docs/stream_lichess.sh b/docs/stream_lichess.sh
@@ -10,13 +10,17 @@ if [ "$1" = "" ]; then
fi
gameid="$1"
-token="API token here"
+token="" # API token here.
url="https://lichess.org/api/board/game/stream/$gameid"
-# start position
+# start position of classical chess.
fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
+white="Anonymous"
+black="Anonymous"
+firstline=1
+
# -N disables cURL buffering, each line is streamed as JSON.
curl \
-f \
@@ -25,9 +29,23 @@ curl \
-H "Authorization: Bearer $token" \
-H 'Accept: application/x-ndjson' "$url" | \
while read -r json; do
+ if [ "$firstline" = "1" ]; then
+ str=$(printf '%s' "$json" | jaq '$1 == ".initialFen" { print $…
+ test "$str" != "" && fen="$str" # override
+
+ str=$(printf '%s' "$json" | jaq '$1 == ".white.name" { print $…
+ test "$str" != "" && white="$str" # override
+
+ str=$(printf '%s' "$json" | jaq '$1 == ".black.name" { print $…
+ test "$str" != "" && black="$str" # override
+
+ firstline="0"
+ fi
+
moves=$(printf '%s' "$json" | jaq '$1 == ".moves" { print $3; }')
test "$moves" = "" && continue
clear
+ printf '%s vs %s\n\n' "$white" "$black"
./fen -o tty "$fen" "$moves"
done
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.